Question by
PetLamb · Nov 29, 2015 at 10:11 AM ·
2d-physics
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 :)
Comment
Best Answer
Answer by NinjaISV · Nov 29, 2015 at 06:14 PM
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;
}
}
Your answer

Follow this Question
Related Questions
The problem with a circular 2D object (ball). 0 Answers
How can I slow the movement of a single rigidbody2D? 2 Answers
Backsliding like a baws 1 Answer
2D Dynamic Lights and Shadows 0 Answers
why does my 2d platformer lags? 1 Answer