- Home /
Need help on making player move towards gameobject, if clicked
Okay so I'm making a fishing script around the same as in Runescape. Basicly you click on the fishing spot and it moves towards it, when you are in range, it will start fishing. I know how to do this, but I do not know the commands since I am 'new' to java scripting. (I would prefer if you helped me in Javascript since that is what I am learning and it's going quite well).
Also I'm not sure if using tags to find the player will do, since it's going to be multiplayer and all players will move towards the fishing spot if someone clicks on it, wont they?
My question is, how do I make the character, go so he is in range of the fishing spot (gameobject in this case)?
function Update () {
if (Input.GetKeyDown("Mouse 0"))
//player walk till he is in range
-
//then activate function that has animation and the fishing script I'll figure out
}
I have something like this atm, can be done in a better way probably, but yeah. Any help appreciated.
Answer by kubci98 · Nov 20, 2013 at 04:57 PM
Maybe Vector3.Lerp could work.
You can also use $$anonymous$$oveTowards or SmoothDamp. $$anonymous$$oveTowards Documentation, SmoothDamp Documentation. All these will just move you from one place to another smoothly, if you want players to move around obstacles, you need AI pathfinding (if you don't have Unity Pro, you will need to make your own pathfinding). Unity Pro pathfinding, AI tutorials after 1.32 (a little more difficult way, you might need watch also previous tutorials (1.1 - 1.8))
Also have look at this - you can use it to find out where player clicked: Input.$$anonymous$$ousePosition
You're my god, thank you, I can use this for so many scripts.
Are you still looking for a way to distinguish your player from the other players?
Your answer
Follow this Question
Related Questions
Unity Enemy Range detection 3 Answers
Player Going through colliders 1 Answer
Orbit player around center point 1 Answer