- Home /
Question by
Haileapp · Jul 21, 2017 at 09:06 AM ·
2d game2d-physics2d sprites
How to Continue Enemy Movement Without Updating the Position
Hi,
I have a 2D Enemy that is moving within a fixed distance.When the game frame is updated,the enemy starts from the initial point.I just want the enemy to continue moving even after the Update().
This is the Code to move the Enemy..
public RigidBody2D myEnemy;
public Vector2 velocity;
float moveSpeed = 4f;
void Update () {
myEnemy.velocity = new Vector 2 ( transform.localScale.x * moveSpeed,0);
}
onCollisionEnter2D(Collision2D coli) {
if (gameObject.tag=="wall") {
Flip();
}
}
Comment