Input axis confusion

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?

1: Use hashes to assign values to parameters in Mecanim, not strings. Strings take far longer to evaluate to a member and too many of those kinds of calls can slow the system down.

2: Use local-space coordinates to set an object at a relative point to the current object. You do this, in this case, by doing something like:

marker.transform.position = transform.TransformPoint(new Vector3(0f, .015f, 0f);

or some such thing. This automatically takes into account the current direction being faced by the object. I’m not sure how this changes using 2D mode, but you’ll figure it out. It should only take one line of code to assign the marker’s position.

3: Watch the animation states in the Animation window while the game is playing. Be sure to click your player in the current scene assets list. When the attack animation is finished, is it releasing itself back to the normal idle/locomotion animation state?

4: If you’re using FixedUpdate, you don’t need Time.DeltaTime as the updates already occur at fixed intervals. That’s only used in the normal Update function.

Thanks for the tips!