1
\$\begingroup\$

I've made an obstacle course with various moving parts to test out movement of a player. In the obstacle course there is a section where there are multiple cubes moves from side to side, and you have to jump from one to the other. But regardless of their speed, I can't seem to get the player to stay on top of any of the moving cubes. I have no clue how to fix this my only guess would be to use materials, but I can't apply any to the character controller. I appreciate any suggestion that you can give. Also the movement is done as an animation that I created in unity in the animation window.

Thanks, Nova

\$\endgroup\$
1
  • \$\begingroup\$ The moment the player makes contact with a cube you know it's on top of it. At this point you can just add the cube's movement vector to the player as well. \$\endgroup\$ Commented Jan 1, 2017 at 12:40

3 Answers 3

2
\$\begingroup\$

You don't have to apply any Force or Velocity to your player. Just set your player child of the current Obstacle, and it will stick to that Obstacle.

void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "YOUR_OBSTACLE_TAG")
{
//This will make the player a child of the Obstacle
myPlayer.transform.parent = other.gameObject.transform; //Change "myPlayer" to your player
}
}

Note : Remember to remove the player from the Obstacle's child list when you jump or leave it

void OnTriggerExit(Collider other)
{
myPlayer.transform.parent = null;
}
\$\endgroup\$
1
  • \$\begingroup\$ This way the player will also stick to the sides of the moving platform \$\endgroup\$ Commented May 13, 2021 at 9:46
0
\$\begingroup\$

Because you are using an animation to move your platforms the physics in unity has no idea that the object is actually moving. That is why your player stays in the same place and eventually falls off. Try applying a force to a rigidbody on the platform. I don't have time to test this right now so let me know how it goes. If you need any more help I'm happy to help.

\$\endgroup\$
-1
\$\begingroup\$

I never used unity but if it's using a physics engine, maybe you could set the friction to the maximum. Or you could add the moving platform's velocity to the player's velocity.

Hope that helps.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .