'How to move and rotate game object in the direction of movement,How to rotate and move gameObject in the direction of movement
I'm doing a top-down shooter in Unity 2D and I'm currently trying to make a fire point, but when a character changes direction of movement, the fire point stays in the same position, but I want it to move and rotate. Sadly i have no idea how to do it.
using System.Collections;
using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed = 5f;
public Rigidbody2D rb;
Vector2 movement;
public Animator animator;
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
if(movement != Vector2.zero)
{
animator.SetFloat("Horizontal", movement.x);
}
animator.SetFloat("Speed", movement.sqrMagnitude);
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.deltaTime);
}
}
enter image description here enter image description here I want it to be like the first picture, but on the opposite side. enter image description here Something like this (I rotated it in photoshop)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
