- Home /
How to move an object accurately while still being able to add physics to it?
Hi guys,
I'm very new to coding and for the past few days I have been struggling with a certain issue. I'm trying to create a game where a sword object constantly follows the mouse, basically moving towards the mouse transform position and stopping when it reaches it. Also you should be able to add forces to the Rigidbody2D of the sword like when It bumps into a wall.
However Rigidbody2D doesn't mix well with any of the means I know of moving an object towards a position (vector2.movetowards or Lerp). I tried making the sword follow the mouse using rigidbody physics but this just resulted in the sword always overshooting the mouse position once it had stopped moving or just in general being hard to control accurately.
Do you guys know any possible fixes for this issue or any other ways of going about this? thanks in advance for the help. :)
Answer by DanielGL · Jan 18, 2021 at 04:04 AM
You can use Rigidbody2D.MovePosition method, see more here: https://docs.unity3d.com/ScriptReference/Rigidbody2D.MovePosition.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613023505im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Many planets gravity attraction problem 1 Answer
MissingReferenceException: Rigidbody2D has been destroyed 1 Answer
How would you check if an object is closer to the bottom side or top side of another object 1 Answer
Performance Issue with RigidBody2D 1 Answer
Unity 2D Apply force in Z Direction 0 Answers