I’m really confused with something that’s happening in my game.
It’s a top down 2d view with the player facing four directions. I have an invisible gameobject (set to marker) that sets itself relative to the player in the direction he’s facing using the input axis. This code runs on the main player:
void FixedUpdate () {
Vector2 movement_vector = new Vector2 (Input.GetAxisRaw ("Horizontal"), Input.GetAxisRaw ("Vertical"));
if (movement_vector != Vector2.zero) {
anim.SetFloat ("input_x", movement_vector.x);
anim.SetFloat ("input_y", movement_vector.y);
if (movement_vector.x > 0) {
marker.transform.position = new Vector2 (transform.position.x + 0.15f, transform.position.y);
}
if (movement_vector.x < 0) {
marker.transform.position = new Vector2 (transform.position.x - 0.15f, transform.position.y);
}
if (movement_vector.y < 0) {
marker.transform.position = new Vector2 (transform.position.x, transform.position.y - 0.15f);
}
if (movement_vector.y > 0) {
marker.transform.position = new Vector2 (transform.position.x, transform.position.y + 0.15f);
}
rbody.MovePosition (rbody.position + (speed * movement_vector) * Time.deltaTime);
}
This code worked fine until I added an attack animation state, then after that the marker just doesnt move. I reverted back, it worked, and broke again when I added the attack state.
Any idea what I’m doing wrong?