!!! Click and Move !!!

got scripts? Need scripts?
Post Reply
User avatar
Asgarth
Posts: 62
Joined: Tue Aug 10, 2010 11:57 am

!!! Click and Move !!!

Post by Asgarth »

Hey guy's.

I have yesterday downloaded untiy3d :D and uhm it's amazing, but well TOTAL NOOB HERE.

I know i should look at all tut's for this, but yeah tiering to look at all :P

Anyways i have a basic question first of all.

How do i make a click and move script :P

I mean, when i click on the ground i move my char there :)

Sincere:
Asgarth aka Michael B
Image
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: !!! Click and Move !!!

Post by SpiritWebb »

I been working with Unity for a while now, and I myself have not figured out how to do it. I would like to know this too...
Image

Image
User avatar
Sakar
Posts: 520
Joined: Thu Apr 23, 2009 2:59 am

Re: !!! Click and Move !!!

Post by Sakar »

I will mess with this idea. Give me an hour or two and I should have something for you guys ;)

EDIT: Here's a UnityPackage I put together. It contains the script and an example scene showing it at work. To import a package click Assets > Import Package

http://dl.dropbox.com/u/837167/ClickToMove.unitypackage
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: !!! Click and Move !!!

Post by SpiritWebb »

Thanks! I will take a look at this as soon as I get home and try it out and let you know! A big help...been trying to search on how to do this for months...
Image

Image
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: !!! Click and Move !!!

Post by SpiritWebb »

It works...great job.

The only problem I am having, is it doesn't register that the ground/plane has changed height. It stays moving on a flat surface, and will go through mountains, etc. The other problem I just tested seems that when you click it, and the smooth is set to 1, it travels almost instantly to that location, not a smooth walk like when using the WASD or arrow keys. Otherwise it works wonderfully.

Any idea on how to correct this?
Image

Image
User avatar
Asgarth
Posts: 62
Joined: Tue Aug 10, 2010 11:57 am

Re: !!! Click and Move !!!

Post by Asgarth »

Sakar wrote:I will mess with this idea. Give me an hour or two and I should have something for you guys ;)

EDIT: Here's a UnityPackage I put together. It contains the script and an example scene showing it at work. To import a package click Assets > Import Package

http://dl.dropbox.com/u/837167/ClickToMove.unitypackage
Many Thanx.
Image
User avatar
Sakar
Posts: 520
Joined: Thu Apr 23, 2009 2:59 am

Re: !!! Click and Move !!!

Post by Sakar »

SpiritWebb wrote:It works...great job.

The only problem I am having, is it doesn't register that the ground/plane has changed height. It stays moving on a flat surface, and will go through mountains, etc. The other problem I just tested seems that when you click it, and the smooth is set to 1, it travels almost instantly to that location, not a smooth walk like when using the WASD or arrow keys. Otherwise it works wonderfully.

Any idea on how to correct this?
The reason it moves on a flat surface is because it casts a ray to an invisible plane at the same height as the player. This could be fixed by having it cast a ray to the world geometry instead.

The moving issue is because I simply Lerp from one position to another. Instead you'd want to move the player on it's Forward vector until it has reached the desired position. You'd also have to check if the player moved past that position, as it is highly unlikely that it will be exact.

I will see if I can come up with any solutions.
SweetRevenge
Posts: 52
Joined: Sun Jul 04, 2010 4:53 am

Re: !!! Click and Move !!!

Post by SweetRevenge »

is there any way to adjust the speed?
User avatar
Sakar
Posts: 520
Joined: Thu Apr 23, 2009 2:59 am

Re: !!! Click and Move !!!

Post by Sakar »

Change the smooth parameter in the editor.
Post Reply

Return to “Scripting/Coding”