- Home /
Question by
C_est_Chouette · Aug 26, 2020 at 09:50 PM ·
mouserigidbody2dforcecursormouseposition
how to make force from mousepointer constant ?
I have a script that grabs the mousepointer location, makes it into direction and then add force to my rigidbody. So when i click, the rigidbody "jumps" toward the cursor. The problem is that the force applied isnt constant , and gets stronger if i'm far away from the rigidbody and weaker the closer the cursor is. are there any ways to make it constant ?
void Update()
{
if (Input.GetMouseButtonDown(0) && jumps_Left > 0)
{
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
direction = (mousePosition - transform.position).normalized;
rigidBody.AddForce(new Vector2(direction.x * force, direction.y * force));
jumps_Left--;
}
...
Comment
Your answer
Follow this Question
Related Questions
Restricting the mouse cursor from entering a certain area 0 Answers
How do I send my cursor to a sprite 2D 1 Answer
How To Check Which Side of The Screen Your Cursor Is On? 1 Answer
Is it possible to not allow the in-game cursor through certain sprites? 1 Answer
Rigidbody2D AddForceAtPosition - adds more force the further away the target 1 Answer