Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

How can i add simple back and forth movement on the Y-axis to an enemy that has velocity on the X-axis attached to it?

$
0
0
Hello, I m creating a 2D horizontal side-scroller shooter and I have enemies being spawned, whose rigidbody component is being used to give them a velocity like so: public class Mover : MonoBehaviour { public float speed; public new Rigidbody2D rigidbody; public bool random; void Start() { if(random) rigidbody.velocity = Random.value* transform.right * speed; { rigidbody.velocity = transform.right * speed; } } } How can i have these enemies also move up and down constantly on the the Y-axis while they are moving with a velocity on the X-axis? Everything i have tried seems to interfere with the velocity of the objects. I am basically trying to create a simply behavioral pattern so as to make the targets less easy for the player to aim. Any ideas?

Viewing all articles
Browse latest Browse all 1488

Trending Articles