[Closed] collision position script controller help
good morning
im trying to figure out this collision position script controller
based on this tutorial :
http://www.rubengarza.com/maxscript-T04-ScriptController.htm
so far its working fine , except for when i try to rotate the main controller
here is a link to the file (max2011) :
https://www.dropbox.com/s/aet1sf23cy6nhen/collition%20pos%20cont%20test%202.rar
any help would be great
also in the maxscript help file , it says about the dependon function :
“This is obsolete in 3ds Max 8 and higher.
You should assign Nodes to User Variables instead.”
will it work the same with using nodes? and is there any difference in performance speed ?
what max version do you use? everything can be done much easier and clear
im using 2014 , but if it would work with lets say 2011 and above it would be best
delete objects
(
p = plane name:"terrain" width:100 length:100 widthsegs:25 lengthsegs:25 wirecolor:green
w = cylinder name:"wheel" radius:5 height:2 wirecolor:orange isselected:on
w.objectoffsetrot = eulerangles 90 0 0
addmodifier p (NoiseModifier fractal:on strength:[0,0,20] seed:2)
c = w.pos.controller[3].controller = float_script()
c.addnode "terrain" p
c.addnode "self" w
c.addtarget "radius" w.baseobject[#radius]
ss = "r = (intersectRay terrain (ray (self.pos + [0,0,terrain.max.z]) -z_axis))
"
ss += "if r != undefined then (r.pos.z + radius) else radius
"
c.setexpression ss
c.update()
)
well… this is correct but not good rig. it works only without rotation and scale. also it locks free Z position.
the right solution is to use transfrom_script and use wheel parent to change wheel’s transform in the world.
thank you denis for the example , much appreciated
i see how it works without the dependson function
you can see in my file , that i tried something different , not for a wheel
i wanted to make a rig helper to detect collision with a muscle mesh or eye ball
or mouth cavity proxy
to use in skinning and prevent penetrations and help keep the shape
in local areas in the rig without going into mesh projection
so i did put the script controller on a point and and parented it to a control spline
and i wanted to use the parent local Z for the ray , so that it would work in any direction
the control object is pointing at
but it behaves strange with rotation
in the file i posted if you scrub the time line , you can see the effect
here is with parent and parent ray cast
delete objects
(
local p, d, s
p = plane name:"terrain" width:100 length:100 widthsegs:40 lengthsegs:40 wirecolor:green
d = point name:"control" pos:[0,0,30] size:10 box:on axistripod:on cross:on wirecolor:yellow isselected:on
in d (s = sphere name:"target" radius:3 wirecolor:orange)
addmodifier p (NoiseModifier fractal:on strength:[0,0,20] seed:2)
addmodifier p (Bend BendAxis:0 BendAngle:-120)
addmodifier p (Bend BendAxis:1 BendAngle:-120 BendDir:-90)
c = s.pos.controller = position_script()
c.addnode "terrain" p
c.addnode "parent" d
c.addtarget "radius" s.baseobject[#radius]
ss = "r = (intersectRay terrain (ray parent.pos -parent.dir))
"
ss += "if r != undefined then (r.pos + parent.dir * radius) * (inverse parent.transform) else [0,0,0]
"
c.setexpression ss
c.update()
)
edited… in case of better transform notification changed “self” to “parent”
thanks !! perfect :bowdown: just what i was looking for
thank you denis .
hey denis , last thing
im trying to add a “maximum distant” for the ray so that after a certain distance from the parent , the result would be [0,0,0]
im trying something like that:
r = (intersectRay terrain (ray parent.pos -parent.dir))
if r != undefined and (distance from ray hit to parent <= max distance value )then r.pos*(inverse parent.transform) + [0,0,radius] else [0,0,0]
but im struggling is there a way to get to get the ray length ?
damn it !
distance r.pos parent.pos <= MAXdis this works…al i had to do is add the .pos :banghead: