Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
2  
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
show 4 more comments

1 Answer

up vote 3 down vote accepted

Your best luck is to learn some matrix math.

You should have some kind of scene graph that establishes the character as a child node of the boat. It then would store it's position relative to the boat.

The boat would have a transformation matrix, you apply that to the child nodes, and the child nodes could stack some more transformations on the matrix letting you move around the boat while moving relative to it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.