- Home /
Unity 2D fliping player with position of mouse,Unity 2D fliping player with mouse
Hello! I'm begginer so please help me with adding to my code, code that i need. I want make something like on video. Player is looking at mouse but it doesn't move in 360 just left and right like on this video https://www.youtube.com/watch?v=AiJfHTdw9DQ&list=LLexq7PpIet4CgVMU7iNwdFA∈dex=2&t=188s
Also I'm leaving here my movement code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class playermovment : MonoBehaviour {
public float moveSpeed = 5f;
public Rigidbody2D rb;
Vector2 movement;
// Update is called once per frame
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}
} ,I'm beginner so can u help me with adding to my code this code that i need. I want make something like on this video that character facing at mouse.
https://www.youtube.com/watch?v=AiJfHTdw9DQ&list=LLexq7PpIet4CgVMU7iNwdFA∈dex=2&t=188s
Also here is my code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class playermovment : MonoBehaviour {
public float moveSpeed = 5f;
public Rigidbody2D rb;
Vector2 movement;
// Update is called once per frame
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}
}
Your answer
Follow this Question
Related Questions
Unity 2D problem with displaying sprites in final build game 1 Answer
Box Collider 2d don't stop the object (prefab) 2 Answers
Copyright Unity? 2 Answers
Creating an app for mobile and browsers 1 Answer
sound.Play() will not work 1 Answer