I try to put my player back with the script, but when the player looks the other way, it moves on the x-axis instead of the z-axis. I have tried using on local but so far I am not getting the right result.
Does the player have dynamic rigidbody? If so, you will need to use rigidbody teleport. Either that or you have some logic that handles movement based on other variables that have not been reset.
This looks odd as well. Sounds like you are trying to rotate 180 degrees, if so as you are getting the euler angles from global space, you should also set them in global space (use this.entity.setEulerAngles).
Yes that is what I do, so if the player stops climbing because he is reaching the ground I rotate the player with his back to the wall and a little bit from the wall (to prevent the player from immediately climbing again without this being the intention).
So with the first lines of code I set the player on the wall by start climbing and with the last line of code I set the player back on the ground by stop climbing.
Here’s an example that moves the blue marker 0.2 units away from the wall based on the normal of the raycast intersection.
In fact, thinking about it, you could use the normal to rotate the player in the correct direction based off the normal instead of having 4 collision volumes per climbable cube.
I implanted your example in my project and this works great! Much better than how it was. Thank you so much for that!
Only for ending the climbing I still have the same problem. I try to use the position and rotation of the hitMarkerEntity (in my case climbPoint) to put the player back on the ground but the offset only takes place on the good axis and in the good direction if I approached the object from the front.
It’s the same problem as the climbing and should use a similar solution. It’s using absolute world coordinates and offsets when it should be positioned relative to the orientation of the wall and ground.
Little tip - you’re needlessly calling getPosition twice. You should be careful to minimize calls to the API. And you are needlessly creating a pc.Vec3. So:
var pos = this.entity.getPosition();
this.entity.setPosition(pos.x, this.groundPoint.y, pos.z + 1);
This code is functionally equivalent but much faster.
It depends on whether you expect it to change over time. If it’s a stationary entity, sure, you could cache the position in the initialize function. But if the entity changes its position over time, then you’ll need to call getPosition whenever you need the latest position.