[SOLVED] Point click movement check on ground collision

Hello, in my game i have a point and click movement that works fine, untill the player is at the top of a hill and i click on the flat ground, in this case the player walk straight suspending in mid-air, how can i check the ground collision to avoid the walk in air issue? Thanks.

Hi @ayrin,

Does your ground has a rigid body component? If that’s the case you can use a rigid body system raycast to find the click point.

https://developer.playcanvas.com/en/tutorials/entity-picking-using-physics

Hi @Leonidas, point and click works fine already, it’s just mid-air walking when different level terrain downhill

Yes, if you are using a plane to get the clicked world points that won’t work with a terrain object.

Also how do you handle pathfinding? Having your character walk from point A to point B, if there is a hill in between then you need to adjust his height.

To do that you can raycast per frame towards the terrain and find the correct height as he walks.

@Leonidas In open fields i don’t use pathfind the player have to walk around objects himself, i use that just in dungeon where the terrain is tiled and i can create a pathfinding, i wanted to add a code to check the player and terrain collision if they not collide the height must be adjusted. that’s my question subject, when climbing up the collision push up the player but when descending the lack of collision don’t stop the linear movement.

If it works already for you when walking uphill, then for downhill you can increase the gravity in your project settings. That’s a common trick for this particular problem:

image

Just tried it, it seems it works better indeed, thanks a lot @Leonidas

1 Like