HI
Thank you for your answers
I will try your code.
Blinkok : what is "pos", in your function ? The position of the object ?
MadBit : thanks, I will try it
I have made a little change, to get a direct path to the target too, and rotate the character in the direction of the target
// Project: 3D Character Clic And Go
// Created: 2023-03-31, by blendman
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "3D Character Clic And Go" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetAntialiasMode(1)
Create3DPhysicsWorld()
Foldstart // create the ground, box and character
ground1 = 1
CreateObjectBox(1,2000,2,2000)
Create3DPhysicsStaticBody(1)
SetObjectColor(1,100,150,50,255)
// create some box
global h=10 // for the size of the box and player
// Size of box :
u = h
// Create 6 crate on the ground
b=8*u // the random position
For i=0 to 5
n = 2+i
CreateObjectBox(n,u,u,u)
SetObjectPosition(n, random(0,b)-random(0,b),15*u,random(0,b)-random(0,b))
Create3DPhysicsDynamicBody(n)
SetObjectColor(n,100,100,200,255)
next
j = i
For i=0 to 3
n = 2+i+j
CreateObjectBox(n,u,u*2,u)
SetObjectPosition(n, random(0,b)-random(0,b),10,random(0,b)-random(0,b))
Create3DPhysicsStaticBody(n)
SetObjectColor(n,150,100,200,255)
next
// create the player
global player, target
player = 100
target = 102
n= player
CreateObjectBox(n, h, h*2, h)
SetObjectColor(n,150,150,150,255)
x = 0
z = 0
SetObjectPosition(n, 0,150, 0)
WalkVelocity = 40
// To create a character
characterOffsetVec = CreateVector3( 0.0, 0.0, 0.0 )
//This vector indicates the axis your model faces forward.
//For example if your model faces down the - Z axis use this vector.
objectOrientationVec = CreateVector3( 0.0, 0.0, 0.0 )
//The crouchScale parameter is 0.0 to 1.0, for examle 0.75 is 75% of the models standing height.
Create3DPhysicsCharacterController(n, 1, characterOffsetVec, objectOrientationVec, 1.2)
DeleteVector3( characterOffsetVec )
DeleteVector3( objectOrientationVec )
Set3DPhysicsCharacterControllerPosition(n, getobjectx(n), getobjecty(n), getobjectz(n))
// target to move
CreateObjectBox(target, h,h,h)
SetObjectColor(target, 255, 100, 100, 255)
// to get the rotation for character
GLobal PlayerRotation
PlayerRotation = CreateObjectBox(h,h,h)
SetObjectColor(PlayerRotation, 255, 255, 100, 255)
SetObjectVisible(PlayerRotation,0)
// set the camera position
SetCameraPosition(1,0,12*h,-12*h)
SetCameraLookAt(1,0,0,0,0)
n= player
u = 2000
x as float
z as float
FOldEnd
do
Print( ScreenFPS() )
Step3DPhysicsWorld()
Foldstart //keyboard
//~ x = 0
//~ z = 0
//~ if GetRawKeyState(39)
//~ x = 1
//~ endif
//~ if GetRawKeyState(37)
//~ x = - 1
//~ endif
//~ if GetRawKeyState(38)
//~ z = 1
//~ endif
//~ if GetRawKeyState(40)
//~ z = - 1
//~ endif
foldend
foldstart // mouse
if GetPointerState()
worldX# = Get3DVectorXFromScreen( GetPointerX(), GetPointerY() ) * u
worldY# = Get3DVectorYFromScreen( GetPointerX(), GetPointerY() ) * u
worldZ# = Get3DVectorZFromScreen( GetPointerX(), GetPointerY() ) * u
worldX# = worldX# + GetCameraX(1)
worldY# = worldY# + GetCameraY(1)
worldZ# = worldZ# + GetCameraZ(1)
obj = ObjectRayCast(ground1,getcamerax(1),getcameray(1),getcameraz(1),worldx#,worldy#,worldz#)
if obj
px = GetObjectRayCastX(0)
py = GetObjectRayCasty(0)
pz = GetObjectRayCastz(0)
SetObjectPosition(target,px,0.2,pz)
move=1
endif
endif
foldend
Foldstart // move the player
if move = 1
x=1
z=1
if abs(px-getobjectX(n)) <0.5
x=0
else
x1=1
endif
if abs(pz-getobjectz(n)) <0.5
z=0
else
x1=1
endif
if x<>0 or z <> 0
SetObjectLookAt(PlayerRotation, px, py, pz,0)
finalRotation =GetObjectAngleY(PlayerRotation)
Move3DPhysicsCharacterController(n, x1, WalkVelocity)
Rotate3DPhysicsCharacterController( n, finalRotation )
SetObjectPosition(PlayerRotation,getobjectX(n),getobjectY(n)-n/2,getobjectZ(n))
SetCameraPosition(1, getobjectX(n), getcameraY(1), getobjectZ(n)-12*h)
SetCameraLookAt(1,getobjectX(n),getobjectY(n),getobjectZ(n),0)
else
Move3DPhysicsCharacterController( n, 0, WalkVelocity)
move = 0
endif
endif
Foldend
Sync()
loop
AGK2 tier1 - http://www.dracaena-studio.com