I'm using this script to move my character in my 2d world:
public float speed; //Movementspeed
public Rigidbody2D rbody;
Animator anim;
void Start () {
rbody = GetComponentInChildren<Rigidbody2D> ();
anim = GetComponent<Animator> ();
}
void FixedUpdate () {
Vector2 movement_vector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
if (movement_vector != Vector2.zero) {
anim.SetBool("iswalking", true);
anim.SetFloat("input_x", movement_vector.x);
anim.SetFloat("input_y", movement_vector.y);
} else {
anim.SetBool("iswalking", false);
}
rbody.MovePosition (rbody.position + movement_vector * speed * Time.deltaTime);
}
}
What I want is to somehow register where my character is facing/walking towards to be able to Instansiate a gameobject infront of it.
How do I do that?