Notifications
Clear all

[Closed] Surface Follow problem

I’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.

5 Replies

could you give us a working example so that we can experiment on?

 JHN

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

Hi crimsonfox,

Please follow this:

  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
				)
			)
		)



	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
				)
			)
		)


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
				)
			)
		)