Need Help With Setting Rotation Of Dynamic Rigidbody Object

I want to set the rotation instantly. I want it to switch to an angle depending on which key is pressed, but I can’t figure out a way that works with the rigidbody. I need help. Is there a way to set the rotation of a rigidbody instantly?

You can use the teleport method on a dynamic rigidbody:

https://developer.playcanvas.com/en/api/pc.RigidBodyComponent.html#teleport

Just make sure not to call per frame or something similar since it comes with a performance hit. Normally you should be using forces/impulses to move rigid bodies, or be setting the linear/angular velocity directly.

1 Like

@Werdie_Alt has tried that, but says the results don’t work correctly. I’ll ask @Werdie_Alt to explain the problems to you, since he’s the one who wants to know the answer.

1 Like

Good, and also a simple sample project would help to debug this.

His plan is to set the rotation instantly. So it’s directly set to 90. The rotation needs to be instant. Teleport might help, but there’s a bug, which (as i stated before) @Werdie_Alt could explain.

I want to set the rotation immediately with a rigidbody so that you can move around differently depending on what rotation you’re in. But that’s not important, I want it to just rotate 90 or -90 degrees depending on which key you press. (EX. you press D and it rotates you +90 degrees on the y so you basically turn right or left)

You can find the common ways to orient an entity here:
https://developer.playcanvas.com/en/tutorials/manipulating-entities/

For example:
`entity.setLocalEulerAngles(0, 90, 0);`

1 Like

I have tried to understand these since the begging of the problem, but it is very hard to understand Euler angles.
(Same account as @BloodStorm0606)

Check the following tutorial on how to use forces and impulses to move your rigid bodies, and also how to use the teleport method to set a precise position/rotation.

https://developer.playcanvas.com/en/tutorials/Using-forces-on-rigid-bodies/

You can’t use the entity translation methods (like setPosition/setEulerAngles) for entities that have rigid bodies.

``````this.entity.setLocalEulerAngles(0, 0, 0, 0);
this.entity.rigidbody.teleport(PositionNueva);
``````

With this it works.

Hi @slam and welcome! Thank you for your contribution. Keep in mind that this is an English speaking forum. That’s why I translated your message.

1 Like