Make player move with a moving platform

I’ve read some about it, but still have yet to find the perfect solution to this.

I have a player (with my own controller script, using rigid body) that jumps mario-style. I’m using iTween on a platform to move it between two points. When the player jumps and lands on the platform, I want him to move with it.

How is this best achieved?

Hey, I haven’t done this before, but I know I’ve seen this asked before on the forums.I believe some people recommended using a trigger, and when the trigger was entered to move both objects at the same time.

As for the results of whether this worked for him or her, I do not know.

I was able to get this to work using the source files for the 2D tutorial and using iTween to move the platforms instead of Unity’s included scripts. My new son should be born any day now so I’m focusing on that but I’ll get you a solution for this as soon as I can.

Does it cause problems to just parent the player to the platform as long as they’re touching? I would think that would do it.

You are absolutely right! I threw together a new example to demonstrate how to do this: iTween for Unity by Bob Berkebile (pixelplacement)

Thanks for your suggestions! Actually the method I’ve tried so far is the one suggested by Vicenti. I found it from this video: http://www.youtube.com/watch?v=K5ObDagGZjI

I’ve had some problems with it however, and that is why I wanted to know if there are anyone who made this work otherwise. The problems might just be me, I’m still debugging alot to make this work.

Problem 1: When my player (a rectangular box with a sphere on top) is parented the platform, the dimentions are totally messed up. Note: For some reason, just today this magically seems not to happen, though it has happened a lot

Problem 2: The player doesn’t fully/smoothly move with the platform. @pixelplacement1: try moving your platforms in the x direction (using your example) and you’ll see what I mean. This might have something to do with the player being a rigid body, I don’t know yet.

@pixelplacement1: thanks a lot for making an example on this! I bought all your examples yesterday, then today I had to get this last one too :wink: (iTween rock!)

So I’ll do some more debugging on this, and get back to this thread. I think the scenario here is something every game developer will face sooner or later making games in unity!

Edit 1: Problem 2 seems to solve itself when I add a rigidbody to the platform and turn off gravity. Which means that so far this seems to work. I will post further problems and solutions to this thread for future reference.

Edit 2: I got an idea of using friction as a means to keep the player on the platform. After all, this is what works in real world. The result was not mindblowing, it kind of worked, but the player bounced up and down as a result of applied friction, and I couldn’t tune it enough to get the desired smoothness. This idea would be perfect (in its universalness), but so far I couldn’t make it work satisfactory.

I’m planning on add a flag to iTween named “physics” which will be a boolean. This flag will cause iTween to operate everything in FixedUpdate() and will also cause it to apply all of its calculations through Rigidbodies. I wonder if this could help with things. I hope to have this complete in the next few weeks.

Thanks for the support!

iTween will now correctly manage and move Rigidbodies! Try out the most recent version and let me know if it helps!

Ignore the previous post about a special “physics” property… if you have a Rigidbody on the GameObject you are trying to move or rotate with iTween; iTween will automatically switch methods internally to animate in FixedUpdate and use MoveRotation and MovePosition.

Enjoy!

Do you mean iTween will now correctly manage and move Rigidbodies?

Sorry, yes. :slight_smile:

The motion seems more smooth at first glance now. I have a slight problem, and I’m not sure if it’s just me or something else.

I have a platform moving between two points in a motion curve set at about 45 degrees. When i jump up and down while on the platform, the player often seems to drift without me moving him.

I uploaded a stripped down version here if you wanna take a look: Free large file hosting. Send big files the easy way!

Thanks a lot for the effort you put into this :slight_smile:

I wasn’t able to find a moving platform in that project link but my first guess would be you need more friction.

That link was to a .rar file containing a very stripped down project. Here is a link to a .zip file instead: Free large file hosting. Send big files the easy way!

Unpacking the .zip you have small project. In the Scenes folder, there is a 0.03.unity file. This scene contains the platform and player.

I tried making a physics material with all friction set to maximum, but still this artifact is happening. Jumping up and down a couple of times while trying to stay on the platform (dont try moving when you land on the platform) and the artifact should be easy to spot.

Found it. Not too sure about this one. This would be something that need to be figured out in the physics engine. I’d recommend doing some searches on the forums on this issue. I’m certain others have had this issue with a character sliding on a moving platform.

Please let me know if you narrow this down.

Thanks!

OK, so I tried to add a physics material with no friction to both player and platform (before I only had on player), and that seemed to help.

Awesome!

Something else that I came across in the docs is the following:

ScriptReference/Rigidbody.MovePosition.html

From the doc:
For kinematic rigidbodies it applies friction based on the motion of the rigidbody. This lets you simulate moving platforms with rigidbodies sitting on top of the elevator. If you want other rigidbodies to interact with the kinematic rigidbody you need to move it in the FixedUpdate function.

Yup. iTween now works in FixedUpdate and with MovePosition when a RigidBody is present or with MoveRotation when rotations are requested.

Nice, I guess I don’t have to think about it then :wink:

Thanks for the ups guys!