- Home /
More Efficient Way to Move Object at Angle
This is definitely a noob question. I've found many questions about angles but as far as I can tell they didn't answer my question. I am working through a tutorial but trying to add things to it to learn. What I would like to do is move an enemy ship at an angle across the screen. It's not trying to reach a position and it doesn't need to rotate. Here is what I'm doing right now:
public float speed;
private Vector3 _direction;
private void Start()
{
// The starting position is randomized when it is spawned. I'm just going to simply make it go right or left based on where it is on the x-axis .
_direction = transform.position.x > 0.0 ? Vector3.left : Vector3.right;
}
private void Update()
{
// I want it to go down at an angle
transform.Translate(Vector3.down * _speed * Time.deltaTime);
transform.Translate(_direction * _speed * Time.deltaTime);
}
In my very simple game this seems to work but I'm wondering if there is a more efficient or more proper way of doing this?
Comment