How to make an object stay relative to another object

Posted by Nick on Game Development See other posts from Game Development or by Nick
Published on 2012-10-10T20:45:10Z Indexed on 2012/10/10 21:56 UTC
Read the original article Hit count: 339

In the following example there is a guy and a boat. They have both a position, orientation and velocity.

enter image description here

The guy is standing on the shore and would like to board. He changes his position so he is now standing on the boat.

enter image description here

The boat changes velocity and orientation and heads off. My character however has a velocity of 0,0,0 but I would like him to stay onboard. When I move my character around, I would like to move as if the boat was the ground I was standing on.

enter image description here

How do keep my character aligned properly with the boat? It is exactly like in World Of Warcraft, when you board a boat or zeppelin.

This is my physics code for the guy and boat:

this.velocity.addSelf(acceleration.multiplyScalar(dTime));

this.position.addSelf(this.velocity.clone().multiplyScalar(dTime));

The guy already has a reference to the boat he's standing on, and thus knows the boat's position, velocity, orientation (even matrices or quaternions can be used).

© Game Development or respective owner

Related posts about matrix

Related posts about vector