x


how could a player (or an object) be moved onto and inside an animated vehicle?

What would be the best way(s) to have the player (and/or an object) move onto an animated object (translating and/or rotating ''vehicle'' for instance) and then be ''transported'' by that animated object while keeping its ability to be moved around by mouse/keyboard control until it 'steps off' that vehicle (like stepping on board of a moving ship, and sitting or walking around while being transported, until finally stepping off the ship)? Would anybody have achieved that sort of thing (or tried to..), and would there be any 'scripts' available for that? (or can it be achieved by applying physics, and in that case, how?) Thanks for any help; any idea or piece of advice would be welcome.

more ▼

asked Dec 26 '09 at 02:26 AM

bruno gravatar image

bruno
51 1 2 3

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Basically, all you need to do is put the player-object under the vehicle-object in the hierarchy. That can be done via Transform.parent. So if you have Transform vehicle and Transform player, to get into the vehicle, simply call

player.parent = vehicle;

Then, when the player leaves the vehicle, simply call

player.parent = null;

In the case where the player steps onto a car that he would control, you'd also need to transfer control (moving the player around with keyboard / joystick / mouse) from directly influencing the player to influencing the vehicle (and back). So, in that case you'd have some sort of "PlayerController"-class to which you either assign the player-object, or the vehicle-object. You might also change the state if the behavior of the vehicle is different from the behavior of the player (which is usually the case). Obviously, those are very game-specific things.

For the example of the ship in which the player can move around (what you asked for), that would be more like a typical moving platform: In that case, you would keep controlling the player but have it attached to the ship. Then, you just need to make sure that any movement of the player is based on Transform.localPosition instead of Transform.position. This is really where having Transform.localPosition shows its full benefit because using that, these kinds of things get very easy to implement.

In Traces of Illumination, I now do have moving platforms that the player can get onto; which is working quite nicely and wasn't too hard to implement. However, the scripts wouldn't help much because I still need to do a lot of stuff specific to that game; so they would be unnecessarily complex (it's networked multiplayer - so that adds a tremendous amount of complexity). But with the information above and the scripting reference, you should have a very good start. Feel free to ask any more specific questions along the way.

more ▼

answered Dec 26 '09 at 08:37 AM

jashan gravatar image

jashan
10.1k 25 40 116

many thanks, I'll study your explanations for the moment and might be interested in 'networked multiplayer' info in a not so remote future.

Dec 26 '09 at 05:25 PM bruno
(comments are locked)
10|3000 characters needed characters left

I guess parenting your objects Transform will certainly do the trick. But there is another way to do this if you don't want to mess with your hierarchy. You could also use a "Fixed Joint". This will attach your player to the moving object's rigidbody. The advantage is that you don't neet to change hierarchy. However this will only work if both objects have a rigidbody component.

more ▼

answered Jan 06 '10 at 04:02 PM

StephanK gravatar image

StephanK
6k 39 53 93

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3787
x2498
x1874
x29

asked: Dec 26 '09 at 02:26 AM

Seen: 2967 times

Last Updated: Dec 26 '09 at 02:26 AM