Sign in to follow this  
Andrey Zimin

Сoordinates to the object

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

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.