Jump to content

Сoordinates to the object


Andrey Zimin
 Share

Recommended Posts

1 hour ago, brianzinn said:

If I understand your question, but otherwise maybe a PG to explain?


objectB.position = objectA.getAbsolutePosition() // may need to .clone() that position

 

 

There is an object Obj it and want to move to the point A. The known coordinates of point A with respect to the global center M. How can I do it using method setLinearVelocity(target)? If I is target put the coordinates of the point M, the Obj moves in the direction of the line L. But if it were possible to specify the target relative to the Obj. How can I do that?

Obj.physicsImpostor.setLinearVelocity(target)

More simply. When you click the mouse, send Obj to where I clicked with setLinearVelocity()

DeepinScreenshot_select-area_20180213225012.png

Link to comment
Share on other sites

Here is a PG that calculates direction from random points (ie: OBJ) to a "target" (ie: A) and draws a cylinder on that direction.  I copied part of another PG:
https://playground.babylonjs.com/#2A0HNY

With 2 points in 3d space when you take the cross product of them you get a vector that is orthogonal/perpendicular to both (the order of arguments will change answer).  If you consider in general that is not straight up you want to go then you can cross product (line 24) with Vector3.Up to get an axis (ie: x or z axis).  The Dot product (line 28) is the cosine of the angle between them.  Anyway, try some of that code as it should point you in the right direction. Otherwise make a PG.

Also, you may just want to apply impulses in that direction instead of setLinearVelocity - depending on what you're doing.

edit: you might have some luck with lookAt function.

Edited by brianzinn
Link to comment
Share on other sites

10 hours ago, brianzinn said:

Here is a PG that calculates direction from random points (ie: OBJ) to a "target" (ie: A) and draws a cylinder on that direction.  I copied part of another PG:
https://playground.babylonjs.com/#2A0HNY

With 2 points in 3d space when you take the cross product of them you get a vector that is orthogonal/perpendicular to both (the order of arguments will change answer).  If you consider in general that is not straight up you want to go then you can cross product (line 24) with Vector3.Up to get an axis (ie: x or z axis).  The Dot product (line 28) is the cosine of the angle between them.  Anyway, try some of that code as it should point you in the right direction. Otherwise make a PG.

Also, you may just want to apply impulses in that direction instead of setLinearVelocity - depending on what you're doing.

edit: you might have some luck with lookAt function.

Thank you! I am created PG. https://www.babylonjs-playground.com/#IFFDYH#1 (click on the ground)

How do I get a value target (line 39) such, that the ball moves in the direction of the mouse click?

Link to comment
Share on other sites

26 minutes ago, JohnK said:

Examining 'pick' in the console shows that 'pickedPoint' is what you need. https://www.babylonjs-playground.com/#IFFDYH#2

No friend! All not just simple! )) The count comes from the global coordinate axes. If I click near the ball at the top left, it will roll in the opposite direction. And all this because of the global reference and direction of the vector. How to fix it?

https://www.babylonjs-playground.com/#IFFDYH#3

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...