I want an enemy to move around the room like a bishop, aka. diagonally.
The problem is that I don't have any idea how to do this, i get that it has to do with vectors, but that's about it.
The code i have makes it go downward and left, but as soon as it bounces it starts to up and right and starts bouncing around the same corner.
here's the code i use:
public class BasicEnemyMovement : MonoBehaviour { [SerializeField] float BounceAngle = 10f; [SerializeField] float speed = 10f;
Rigidbody2D EnemyRigid;
private void Awake()
{
EnemyRigid = GetComponent<Rigidbody2D>();
EnemyRigid.velocity = new Vector2 (-BounceAngle, -BounceAngle);
}
// Update is called once per frame
void Update()
{
}
private void OnCollisionEnter2D(Collision2D collision)
{
//BounceAngle = BounceAngle + 90;
Vector2 velocityTweak = new Vector2(BounceAngle, BounceAngle);
EnemyRigid.velocity = velocityTweak;
}
}
Comment