- Home /
How to make a rigid body move along a specific path using my mouse?
The game features 2d circular characters that are supposed to have rectangular shaped weapons that orbit the character. The weapon is supposed to follow and point towards the mouse, but still travels along a path around the character.
(Sorry i currently don't have access to my pc right now so here is a little ms paint thing)
However one of the big issues is that i would like this weapon to be a physics object with a high mass, as to simulate the physics of a heavy sword that you must use to knock other enemy's swords away so that you can land a clean hit.
I eventually also have to make enemies with their own swords, so it would be ideal if i could easily edit the path i want the sword to take. For example: if the enemy is within x distance of the player, the enemy should move their sword to x position/angle at x speed. Any suggestion helps!
Answer by tormentoarmagedoom · Oct 09, 2019 at 02:46 PM
Hello there.
You shoud combine this 3 functions:
https://docs.unity3d.com/ScriptReference/Input-mousePosition.html
https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
https://docs.unity3d.com/ScriptReference/AI.NavMeshAgent.SetDestination.html
Good luck!
Ah the navmesh function looks Interesting. Are you suggesting that i use set points that the weapon goes to based on my mouse position?
Yea, you only need to order the navemesh agent to move towards the mouse position while mouse is clicked.
Your answer
Follow this Question
Related Questions
How to boxcast where a dynamic rigidbody2D's box collider will be in the next frame? 1 Answer
More realistic physics on child collisions 2D 0 Answers
Set player and enemy RigidBodies so that neither can push the other 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers