Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Moving player to the opposite direction where the mouse is

$
0
0
Hello, I've been trying to make it so that my player gets propelled to the opposite direction to where the user makes a mouse click. The following code was applied to the player. I can't get it to work even though the DrawLine debug works and the Debug.log for 2DForceVector works too. Hopefully you can help me. Thanks in advance. var movementMaxVelocity : float = 10; var jumpSpeed : float = 3; var movementForce : float = 10; var mouseVectorPosition : Vector2; var playerVectorPosition : Vector2; var 2DForceVector : Vector2; function Update () { mouseVectorPosition= Camera.main.ScreenToWorldPoint(Input.mousePosition); playerVectorPosition = transform.position; 2DForceVector = (mouseVectorPosition - playerVectorPosition).normalized; rigidbody2D.AddForce(2DForceVector * movementForce * -1); }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>