- Home /
How to rotate a gameObject's inertia?,How to rotate gameObject with its inertia?
Hello. First time poster here.
As in the preceding image, the purple arrows represent the player's position and rotation. The black arrows represent how the character moves when subjected a impulse of force and gliding through the portals, which are represented by the blue and orange lines, without any additional force after the inital impulse and there is no friction. I intended to make it behave like the portals in Valve's Portal and Portal 2, but the inertia is not rotating with the player and goes to the same world-space direction even if the player itself rotated. How should I rotate the inertia to make it match the player's rotation while the player is going though the portals? Thanks in advance.
Answer by s_awali · Nov 23, 2018 at 11:42 AM
My bet is you need to modify the velocity property of the rigidbody of your player. You'll first need to calculate the difference between the two portals rotation, and apply this difference to the velocity of your rigidbody.
To get the difference of two Quaternion, use this function :
var diff = PortalA.rotation * Quaternion.Inverse(PortalB.rotation);
Next, you'll need to apply this to the velocity of the player. My guess is that the following code should work:
Rigidbody.velocity = diff *Rigidbody.velocity;
Some tweeking might be needed.
Big thanks! However I just solved it 1 $$anonymous$$ute before I read your great answer(literally 1 $$anonymous$$ute, serious) while I was reading This answer
Your answer
Follow this Question
Related Questions
Is there an easy way to make my camera lag behind the vehicle? 1 Answer
Compute the torque needed to rotate an object at a constant rate 3 Answers
How do you calculate DeltaX and DeltaZ for a character? 1 Answer
manually calculating Moment of Inertia 1 Answer
How to calculate inertia tensor and tensor rotation manually 2 Answers