- Home /
Set movement speed on collision,movement speed on collision
This may seem a silly question, but I have been searching and still got no answer. I have a scene like this; https://gyazo.com/c6c0515607fd36327607ba8888a0eb91
When the robot's foot game object collides with the treadmil, I want to make it to start moving. I am sure the collision is right, and I got no error on referencing the robot's foot game object (the script is on the treadmil).
public class MOVEMENT : MonoBehaviour {
private Rigidbody2D MYRIGIDBODY2D;
[SerializeField]
private float MOVEMENTSPEED;
//Get robot
GameObject ROBOT;
private Rigidbody2D ROBOT_RIGIDBODY2D;
// Use this for initialization
void Start () {
ROBOT = GameObject.FindGameObjectWithTag("robot");
ROBOT_RIGIDBODY2D = ROBOT.GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate () {
}
void OnCollisionEnter2D(Collision2D coll)
{
if(coll.gameObject.tag == "robot")
{
ROBOT_RIGIDBODY2D.velocity = new Vector2(MOVEMENTSPEED, 0);
//Debug.Log(ROBOT_RIGIDBODY2D);
Debug.Log("hit");
}
}
Is there something that I missed? If i set the velocity on the FixedUpdate, the robot's foot will move though. Can someone help me? ,
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Unity 2D - How do I add the velocity and direction of an object to another object? 2 Answers
Predict Spherical Ball Collision Direction 1 Answer
Move until collision sticks 0 Answers
Multiple Cars not working 1 Answer