[Closed] help .. how can i make object distance
hi all …
i know how to measure a distance between tow objects …
but hoe can i move this tow objects to have a certain distance between them …
Could you put it inside a loop, give the child object a “direction” to move in and incremental about and “push” the object until it reaches the desired distance?!?
You could also create a spline/line which is the length you need it, point through the child object and move the child object to the end of the spline/line…???
Just a couple of ideas…and no, I have no idea how I would actually do it
Shane
To measure distance, we can take the position of object A, and subtract the position of object B, and get the length() of the resulting point3 value. We can then take the resulting vector and normalize() it. This will give us the direction vector between the two objects.
A normalized vector has a length/magnitude of 1. We can take this direction vector (the normalized subtracted numbers) and mutiply it by our desired distance to make it the proper length. We also need to add in the original position (or it will be relative to the origin), and we will have a properly offset object along the same vector with a distance of your choosing.
This code should work as something to start from:
a = selection[1]
b = selection[2]
subVec = a.pos - b.pos
origDist = length subVec
normVec = normalize subVec
newDistance = 250
newPos = normVec * newDistance
newPosBias = newPos + b.pos
a.pos = newPosBias
Just figured that out now so I’m going to pat myself on the back
thx guys …
but what i had in minde like to have it on R_click and enter the desierd distance …
Are you asking how to capture the value on right click or how to calculate the distance? If you’re asking about the calculation, you use exactly the code that Professor420 gave you, but you replace the 250 with the distance the user input.
If you’re asking how to capture the number, you need to write a macroscript that prompts for the value and assign it to a quad menu (this is in the help). But, I think you’re going to need more input than that. The user right clicks on an object, you prompt for a distance, but you also need to know what object you want to be that far away from (make any sense)? Or maybe I’m not getting what you’re asking.
(And prof420 – nice name btw – you don’t need the line ‘origDist = length subVec’ in your code as you don’t need the original distance to calculate the new distance.)
“but what i had in minde like to have it on R_click and enter the desierd distance …”
yeah, you can ask for right click “MAKE AMAZING PICTURE” too…