Create object in air that moves only on impact? (2D)

Hello there,

I’d like to create a cube in air, and make it only move when another Rigidbody hits it.

Thanks :slight_smile:

You could just set the Gravity Scale on the cube’s Rigidbody2D to 0. Then it would go flying when it was hit, but it would have no gravity on it. Is this what you’re looking for? If not, you could just have the Gravity Scale as 0 like before, but add a script to the cube that sets the Gravity Scale to 1 on collision. It would look something like this:

using System.Collections;
using UnityEngine;

public class Cube : MonoBehaviour {
	Rigidbody2D rigidbody2d;

	void Awake () {
		rigidbody2d = GetComponent<Rigidbody2D> ();
	}

	void OnCollisionEnter2D (Collision2D other) {
		rigidbody2d.gravityScale = 1;
	}
}