PDA

View Full Version : Surface Follow problem

 Crimsonfox12-12-2010, 06:07 PMI've got this on roll open do ( (when transform \$b changes id:#shipMove do ( if chk1.checked == true then ( posPos = [\$b.pos.x, \$b.pos.y, \$b.pos.z + 1000] Uray = ray posPOS [0,0,-1] IUray = intersectRay \$p Uray if IUray == undefined then ( print "bleh" ) else ( \$b.pos = IUray.pos norm = -IURAY.dir rightVector = normalize(cross IUray.dir Norm) upVector = normalize(cross rightVector Norm) q = matrix3 rightVector upVector Norm [0,0,0] rotate \$b q.rotation print q.rotation ) ) ) when transform \$p changes id:#surfaceMove do ( if chk1.checked == true then ( posPos = [\$b.pos.x, \$b.pos.y, \$b.pos.z + 1000] Uray = ray posPos [0,0,-1] IUray = intersectRay \$p Uray if IUray == undefined then ( print "bleh" ) else( \$b.pos = IUray.pos norm = -IURAY.dir rightVector = normalize(cross IUray.dir Norm) upVector = normalize(cross rightVector Norm) q = matrix3 rightVector upVector Norm [0,0,0] rotate \$b q.rotation print q.rotation ) ) ) on roll close do ( deleteAllChangeHandlers id:#shipMove deleteAllChangeHandlers id:#surfaceMove ) Problem is it doesn't do the same thing. \$b is the box I want to move along the surface \$p being the surface. I want it to move along the surface when either are moved. It does it fine when \$b is moved just not \$p, the rotation seems to be rotating the opposite way. any help would be great, cheers.
MatanH
12-13-2010, 07:09 AM
could you give us a working example so that we can experiment on?

JHN
12-14-2010, 11:39 AM
skinwrap a nurbs surface to the water and use a surfaceDeform on a small plane, then an null with an attachment constraint to the plane and add some controls to animate over the U an V.

-Johan

batigolnguyen
12-15-2010, 05:13 AM
Hi crimsonfox,

1. rotate function will accumulate all rotation value --> you should set the rotation matrix directly

2. You should define the direction vector to [1,0,0] (it is upvector in your code)

3. You should move the setting position of b after setting rotation

Hope this helps,
--Batigol

on roll open do
(
when transform \$b changes id:#shipMove do
(
if (chk1.checked == true) then
(
Uray = ray [\$b.pos.x, \$b.pos.y, \$b.pos.z + 1000] [0,0,-1]
IUray = intersectRay \$p Uray
if IUray == undefined then ( print "bleh")
else (
norm = IURAY.dir
rightVector = normalize (cross [1,0,0] norm )
upVector = normalize (cross rightVector norm)
--q = matrix3 rightVector upVector Norm [0,0,0]
q = matrix3 upVector rightVector norm \$b.pos
--rotate \$b (q.rotation)

\$b.rotation = q.rotation
\$b.pos = IUray.pos

--print q.rotation
)
)
)

batigolnguyen
12-15-2010, 05:16 AM
on roll open do
(
when transform \$b changes id:#shipMove do
(
if (chk1.checked == true) then
(
Uray = ray [\$b.pos.x, \$b.pos.y, \$b.pos.z + 1000] [0,0,-1]
IUray = intersectRay \$p Uray
if IUray == undefined then ( print "bleh")
else (
norm = IURAY.dir
rightVector = normalize (cross [1,0,0] norm )
upVector = normalize (cross rightVector norm)
--q = matrix3 rightVector upVector Norm [0,0,0]
q = matrix3 upVector rightVector norm \$b.pos
--rotate \$b (q.rotation)

\$b.rotation = q.rotation
\$b.pos = IUray.pos
--print q.rotation
)
)
)

batigolnguyen
12-15-2010, 10:30 AM
Try this one, I made some modification and it worked on my pc

on roll open do
(
when transform \$b changes id:#shipMove do
(
if (chk1.checked == true) then
(
Uray = ray [\$b.pos.x, \$b.pos.y, \$b.pos.z + 1000] [0,0,-1]
IUray = intersectRay \$p Uray
if IUray == undefined then ( print "bleh")
else (
norm = IURAY.dir
rightVector = normalize (cross [1,0,0] norm )
upVector = normalize (cross rightVector norm)
--q = matrix3 rightVector upVector Norm [0,0,0]
q = matrix3 upVector rightVector norm \$b.pos
--rotate \$b (q.rotation)

\$b.rotation = q.rotation
\$b.pos = IUray.pos
--print q.rotation
)
)
)

CGTalk Moderation
12-15-2010, 10:30 AM
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.