Be the first to post for 'Moving Rigidbodies Smoothly'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

I tackled this “sliding frog” problem myself a little while ago, and I came up with this solution:

All gameobjects are the Frog can use to move (in our case, this is just the logs) are tagged with “Platform”. The Player script then gets the following OnCollisionStay method:

private void OnCollisionStay(Collision other)
 {
	transform.parent = other.gameObject.tag == "Platform" ? other.transform : null;
 }

So whenever the player is touching a “Platform” object, it’ll be childed to the “Platform” and will move with it. Otherwise it has no parent, and will be at the root level of the hierarchy.

I much prefer your solution with the Rigidbody, though - this makes parameters such as friction tweakable. Making the logs slippery could prove a challenge to the player. :slight_smile:

Also, a small nitpick: why not use Vector3.left instead of subtracting the Vector3.right in Line 14 of PlayerMovement.cs? That makes the code much easier to read IMO.

Privacy & Terms