Help needed for small script

Hi,
I’m looking for a simple script for moving one object in z axis controlled by other object. The way I see this would be to get first the z position of the pivot point from the control object via script, and then apply it to the z axis of the one that I want to move.

I know that there are ways, other than scripting, for doing this but those won’t work in the case I have. I must say too, that I have no idea of scripting.

thanks in advance,
Manuel

Why not Wire the Params ? Will do the same as scripting it.

As for scripting :

Assign a Float script controller to the Z channel of the child object
In the script controller create a variable and assign it to the parent node
use this variable to access the z possition as follows :
box.pos.z
where “box” is the variable name.

Regards,
Thorsten

Thanks Thorsten,

now that you said that wire and scripting is the same maybe I’m going in a wrong direction. I’ll try to explain the case:
I’m trying to get people walking in a scene where the terrain has slopes. So, I have a mesh “people” with point cache that walks straight in the z axis. Then, I have an object, for example a plain, which follows the surface slope using “conform” space warps. I want the object “people” driving the movement of the plain through the surface in xy axes, that’s easy using an “attachment constraint” (the plain get the z position from the conform surface). Ideally, I would like to find a way where the object “people” get back the z axis info from the plain but via wiring is not working. Do all this process has any sense to you?

Thanks again for your help.

Manuel

just to get that straight. You got ppl walking and they should stick to a groundplane ? If so i’d suggest using a raycast to directly get the z-height of the plane for the object’s x/y position.

Regards,
Thorsten

yeah, you got the idea but I don’t know what you mean by “raycast”

Regards,
Manuel

raycasting is a built in function in maxscript. basically it simply casts a ray into the scene looking for a specified object. If the ray intersects that object the function returns the coordinates of the intersection. Quick example :

  • Create a plane
  • Add a noise modifier and raise the z-strength
  • create a dummy above the plane
  • add a FloatScript controller to the dummy’s Z-Coordinate
  • Create a Variable called “floor” and assign it to the plane node
  • Create a Variable called “position” and assign it to the Dummy node itself

Then use the following script :

 P = position.position
local iRay= ray P [0,0,-1]
z = IntersectRay Floor iRay
z.pos.z+50

Short explanation:

P = position.position
Creates a new Variable holding the Dummy’s position (remember, the Variable referring to the Dummy is called “position” hence the weird position.position
local iRay= ray P [0,0,-1]
Creates a local variable called iRay that is a ray (vector) from P (the Dummy’s position) Straight downwards
z = IntersectRay Floor iRay
Intersects the Ray created as iRay with the Floor node and store the result in a variable called z
z.pos.z+50
Return the final result. z.pos.z is the z component of the intersection coordinates. The + 50 is used to offset a dummy upwards. You’ll have to adjust that one to fit your needs. If you move the dummy in the x/y plane now it will automatically adjust its z-position in realtime.

A short warning, this is rather bruteforce and will fail if the dummy is moved outside the plane’s x/y dimensions as there are no errorchecks or anything.

Regards,
Thorsten

wow, that’s nice! Looks difficult though; but I will try it.

Many thanks,
Manuel