# How to make an object stay relative to another object

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

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

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.

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));

``````

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).

-
Some of the answers to this similar question may help a little with the rotation aspect of this – John McDonald Oct 10 '12 at 20:52
Is this being driven by a physics engine? That's the part I'm unsure about, because otherwise it would be simple to solve using a scene graph. All you would have to do was add the character as a child to the boat node when they first establish contact. Conversely, once the character left the boat, all you would have to do was detach him from the boat node and re-add him to the root node of the hierarchy. Parenting and keeping the relations between nodes is already an integral part of the scene graph. – David Gouveia Oct 10 '12 at 21:00
What have you tried? You're essentially just going to apply the of the boat transforms to the character too. Then apply the rotations of the character in that reference. – Byte56 Oct 10 '12 at 21:01
@David Gouveia Unfortunately I can't use a physics engine (use WebGL) – Nick Oct 10 '12 at 21:04
@Nick You misunderstood. If you were using a physics engine it might be more difficult to implement a scene graph. If you're not using one, then it should be be a good solution. I've googled for "WebGL scenegraph" and found a few ready solutions. Give them a try. Basically what you want in the end is a system where you can simply do `boat.children.add(character)` and everything else works automatically. – David Gouveia Oct 10 '12 at 21:11