#How to rotate a characterbody3d without clipping through objects?

1 messages · Page 1 of 1 (latest)

modest willow
#

Sorry for the long explanation, any help is appreciated!!

undone thorn
#

I am not sure I understand your explanation, but the first thing I would check is if you have collision shapes. Also I think if you just set the rotation it won't check for colissions during the movement I believe you need to use the move_and_slide function for that. I am a begginer myself so I might be wrong about that, and I am not sure I understood your problem enteirly.

modest willow
#

when i rotate the object ( which i do by calling rotate_object_local(Vector3.FORWARD, deg_to_rad(15)) )

#

it clips through the wire

undone thorn
#

ah. I understand. it;s much clearer now.

modest willow
#

I believe it’s calling move_and_slide() but is this incorrect? and there are collisionshapes as you can see in the scene tree in the first image

undone thorn
#

So if I understand it correctly (that is a big if, I'm new too) when you call rotate_object_local it will just rotate the object and ignore collision. What you want to do is instead give it a rotational velocity and then call move and slide. If you want to keep rotation by 15 degree steps I would maintain a target rotation and lerp the velocity towards the target each physics step, that will make the motion feel smoother, even if it is technicaly less responsive.
Also move and slide returns true if there was a colision which seems usefull for your game.

modest willow
undone thorn
#

you could just clam the value and roll over at +-180. and hmm let me take a look at the documentation and figure that out... as I sais I am very new to this too.

modest willow
undone thorn
#

Hmm the more I look into it the more confused I get. RigidBody has velocity and angular velocity but the characterbody doesn't have that. I think I need to do a bit more reading on how this is supposed to work.

#

And a rotation of -181 degrres or +179 is identical if it isn't there is probably a math error somewhere.

modest willow
#

i believe that with rigidbody, it's actually governed by the laws of physics while characterbody is meant to allow for more player control

#

alittle afraid that i might just have to completely redo the player object as a rigidbody to get this to work...

undone thorn
#

It should be fairly easy to swap over, and character body probably works? not sure. Anyway for warpign the angles didn't wrapf(value, -180, 180) work? it should give you full 360 rotation. Anyway CharacterBody seems to only have velocity not angular velocity which confuses me from a physics engine, but it makes sense when controling a character. I am afraid I am a bit out of my depth here. But I suspect the cliping issue is in part because you apply rotation in 15 degree chunks.

So as a solution what I would do is create a new variable, call it target_rotation, and a constant, lets call it ROTATION_SPEED. Then instead of rotating the object you rotate the target_rotation vector each time you get input. Then in your physics step you apply the rotation as follows; rotation_degrees= rotation_degrees.lerp(target_rotation, delta * ROTATION_SPEED)

What that will do is that you will move in far smaller steps and so you will have more opertunities to catch collisions. It will not be 100% reliable esspecialy not at low frame rates but I think that might work. Setting ROTATION_SPEED to the right value might take some tinkering to get the responsiveness you want.

#

I hope that helps? Give it a try at least. Or maybe someone will chime in with a better solution.

modest willow
modest willow
#

should i repost in advanced-help? i dont want to spam but idk if im gonna get any traction rn

undone thorn
#

not sure I haven't gotten any replies on any of my requests for help either, and I certainly don;t feel like an advanced user.

modest willow
#

no worries thanks anyways :)