Jump to content

Moving to mouse point the correct equation


Dwengo
 Share

Recommended Posts

I feel like this is an issue that must have been solved and is a simple algorithm, but I'm struggling to figure it out myself..

https://playground.babylonjs.com/#6R8BFY#11

The problem I'm having is that if I click on the ground (so that the mesh moves towards it). If the destination point is not perfectly diagonal or straight, then the x axis or the z axis is reached first.

It kind of goes diagonally for a bit before going straight for the rest of the route.

The code is really simple, And my feeling is the movement logic needs improving. I'm essentially applying a force of 1 or -1 on each axis depending on where the mesh is currently until it reaches its point.

Is there a better way to do this?

 

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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...