PDA

View Full Version : help .. how can i make object distance


abusakher
12-20-2007, 05:36 PM
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 ...

RustyKnight
12-20-2007, 09:31 PM
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

RobGalanakis
12-21-2007, 03:16 AM
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

abusakher
12-21-2007, 03:31 AM
thx guys ...

but what i had in minde like to have it on R_click and enter the desierd distance ....

focomoso
12-21-2007, 06:12 AM
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.)

gasmasocet
12-21-2007, 01:47 PM
"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...

CGTalk Moderation
12-21-2007, 01:47 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.