Andrey Zimin Posted February 13, 2018 Share Posted February 13, 2018 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! Quote Link to comment Share on other sites More sharing options...
brianzinn Posted February 13, 2018 Share Posted February 13, 2018 If I understand your question, but otherwise maybe a PG to explain? objectB.position = objectA.getAbsolutePosition() // may need to .clone() that position Quote Link to comment Share on other sites More sharing options...
Andrey Zimin Posted February 13, 2018 Author Share Posted February 13, 2018 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() Quote Link to comment Share on other sites More sharing options...
brianzinn Posted February 13, 2018 Share Posted February 13, 2018 (edited) 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 February 13, 2018 by brianzinn Quote Link to comment Share on other sites More sharing options...
Andrey Zimin Posted February 14, 2018 Author Share Posted February 14, 2018 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? Quote Link to comment Share on other sites More sharing options...
JohnK Posted February 14, 2018 Share Posted February 14, 2018 Examining 'pick' in the console shows that 'pickedPoint' is what you need. https://www.babylonjs-playground.com/#IFFDYH#2 Quote Link to comment Share on other sites More sharing options...
Andrey Zimin Posted February 14, 2018 Author Share Posted February 14, 2018 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 Quote Link to comment Share on other sites More sharing options...
JohnK Posted February 14, 2018 Share Posted February 14, 2018 Better? https://www.babylonjs-playground.com/#IFFDYH#4 Arte, brianzinn and Andrey Zimin 2 1 Quote Link to comment Share on other sites More sharing options...
Andrey Zimin Posted February 14, 2018 Author Share Posted February 14, 2018 10 minutes ago, JohnK said: Better? https://www.babylonjs-playground.com/#IFFDYH#4 I knew that there must be a very simple solution) Thanks a lot! JohnK 1 Quote Link to comment Share on other sites More sharing options...
brianzinn Posted February 14, 2018 Share Posted February 14, 2018 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 Andrey Zimin 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.