- Home /
player move while mouse move.
I would like to move player while the mouse move on X axis my code as follow: public class move : MonoBehaviour { public Camera cam; private Rigidbody2D ping;
// Use this for initialization
void Start()
{
ping = gameObject.GetComponent<Rigidbody2D>();
if (cam == null)
cam = Camera.main;
}
// Update is called once per frame
void Update()
{
Vector3 iniPos = cam.ScreenToWorldPoint(Input.mousePosition);
Vector3 targetPos = new Vector3(iniPos.x,0f,0f);
ping.MovePosition(targetPos);
}
}
Comment
Your answer
Follow this Question
Related Questions
Can someone help me with my TPS Controller/Camera? 1 Answer
Why does it seem that rigidbody seems of when moving the character? 1 Answer
Vertical mouse input inverted when player is turned around 0 Answers
How can I make player move with cursor?,How can I make player move with mouse? 1 Answer
Making my 2d character's arm follow the mouse, scrpit not working, please help :c 1 Answer