Hi everyone, I’m simply trying to make a ball move in random directions (and bounce off the sides of the walls), and this is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyEasyAI : MonoBehaviour {
public Rigidbody2D rb;
public float speed = 1;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D> ();
}
void FixedUpdate(){
Vector2 Movement = new Vector2 (Random.Range(-1, 1), Random.Range(-1, 1));
rb.AddForce (Movement);
print (Movement);
}
}
However, what happens whenever I execute the script is that the gameobject simply moves down and to the left, and then stays put at the corner (the corner of the wall where it is being blocked by the colliders). How can I edit it so that the ball moves in a random and sporadic fashion? Any help would be appreciated.