Hello, my player is parented to the platform OK if I move its position, but if I want a platform to move in a constant direction by applying velocity, the player just slides off. I’ve read what I could in other answers, but haven’t found exactly what I need. Here’s the code I’m trying to use:
using UnityEngine;
using System.Collections;
public class MoveWithScript : MonoBehaviour {
void OnCollisionEnter2D (Collision2D other)
{
if (other.gameObject.tag == "Player") {
other.transform.parent = gameObject.transform;
other.gameObject.rigidbody2D.velocity = gameObject.rigidbody2D.velocity;
}
}
void OnCollisionExit2D (Collision2D other){
if (other.gameObject.tag == "Player") {
other.transform.parent = null;
other.gameObject.rigidbody2D.velocity = other.gameObject.rigidbody2D.velocity;
}
}
}
Thanks for reading. Your help is greatly appreciated