# hot Сoordinates to the object

## Recommended Posts

Hi friends! Is the object A is object B. Is there a way to give new coordinates to the object B, but so that the center coordinates was the object A? But object a does not become the parent of object B!

##### Share on other sites

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

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

##### Share on other sites
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()

##### 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 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 on other sites

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

##### 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?

##### Share on other sites
10 minutes ago, JohnK said:

I knew that there must be a very simple solution) Thanks a lot!

##### Share on other sites

Glad you got it - a PG always helps!  Right now the ball velocity is a factor of how far the mouse click is from the ball.  If that is not how you wanted it, you can normalize and/or scale that vector to control the speed:
https://www.babylonjs-playground.com/#IFFDYH#5