Jump to content

New script : move character to mouse position


YouGroove
 Share

Recommended Posts

http://www.leadwerks.com/werkspace/files/file/528-move-character-to-mouse-position/

 

Could be usefull for beginners or people needing some ready to use base code for "move to mouse character system".

 

Enjoy smile.png

 

 

I will bring some improvements as i use it in my own project, like more camera controls, or special visibility when character is hidden behind 3D models.

Stop toying and make games

Link to comment
Share on other sites

If i duplicate the crawler , why only one go to the point i clicked ? as they use same code ?

Did i missed something huh.png ?

 

Another point : The character orients to a strange direction when it reached the goal position using GotoPoint ,instead of keeping facing the direction given , it is a bug ?

post-3271-0-13654000-1398295420.jpg

Stop toying and make games

Link to comment
Share on other sites

When I do this I always call Stop() when within a certain distance of destination. What you are seeing is probably floating point errors or something like that.

 

As for your other problem you are using MouseHit() which will only register once per frame so it's registering for 1 enemy but not the other because they get processed in the same frame. That's my guess anyway with just looking at the code. One way to get around this and simulate a hit function like that is to give each script a bool value for mouse down and then do:

 

if window:MouseDown(1) == true and self.mouseDown == false then
-- do code here on mouse down
self.mouseDown = true
else if window:MouseDown(1) == false and self.mouseDown == true then
-- do code here on mouse up after mouse down
self.mouseDown = false
end

  • Upvote 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...