Question by
Maniac567 · Sep 29, 2015 at 02:50 AM ·
collisionmovementcollidercollision detectionbounce
How can I make an object moving on its own bounce off walls
I'm trying to make an object, moving on its own, going one direction, to go the opposite direction when it collides with a wall. I have done some things, like making the walls I want the ball to bounce off of prefabs, but I am stuck on what I should do next.
Here is my code so far:
using UnityEngine;
using System.Collections;
public class enemyControler : MonoBehaviour {
public float speed;
void Update ()
{
transform.Translate (transform.forward * speed * Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
}
}
Comment
But don't you also need to initialize variables for speed, deltatime and forward?
Answer by hexagonius · Sep 29, 2015 at 01:47 PM
don't translate, use addforce. attach a rigidbody and a physics material with full bouncyness.
Your answer
Follow this Question
Related Questions
How do I count Hits ?? 2 Answers
Rigidbody going through Colliders help! 1 Answer
Collision With Text 0 Answers
how do I let a player pass through a wall when it is the same color? 0 Answers