playMaker

Author Topic: align object rotation to floor...using raycast normal? (SOLVED)  (Read 6412 times)

Digitom

  • Junior Playmaker
  • **
  • Posts: 61
Hey guys.

I am trying to spawn a "tower" in front of my controller, similar to Orcs Must Die, and place the tower on the floor or terrain. My problem is, whenever the floor is angled, my tower does not align with the floor.

-I have tried casting a ray, getting the hit position, normal.
-Set the position of the tower to the hit position.
-I round the vector so the tower snaps to a 1x1 grid system
-I use the "get quaternion from rotation" custom action. From Direction = HitPosition, to direction = HitNormal
- rotate the tower to that quaternion

but I get mixed results, where my tower kinda gimbals around my player. I have also tried casting a ray straight down from my tower, still doesnt rotate the way I want it to.

I found a code to align objects from the unity website...so in theory...this should work?

//with this you rotate object to adjust with terrain
     transform.rotation = Quaternion.FromToRotation(Vector3.up, rcHit.normal);

Anyways I am stumped...I am sure somebody on the forums here have tried aligning objects with the floor at some point making their game? any help is appreciated! Thanks.
« Last Edit: April 30, 2015, 03:37:33 PM by Digitom »

Digitom

  • Junior Playmaker
  • **
  • Posts: 61
Re: align object rotation to floor...using raycast normal? (SOLVED)
« Reply #1 on: April 30, 2015, 03:40:47 PM »
to align an object to the ground in playmaker:

you need to have a Vector3 of (0,1,0)...this is equivalent to Vector3.up
and the raycast hit normal of (x,x,x)

throw those in the GetQuaternionFromRotation action and it works!


flora

  • Playmaker Newbie
  • *
  • Posts: 47
Re: align object rotation to floor...using raycast normal? (SOLVED)
« Reply #2 on: May 01, 2015, 09:52:14 AM »

thank you for the update  :)
it's gonna be very handy!

vyn_halcyon

  • Playmaker Newbie
  • *
  • Posts: 9
Re: align object rotation to floor...using raycast normal? (SOLVED)
« Reply #3 on: May 02, 2016, 06:11:06 PM »
OMG thanks so much for figuring this out.

Such a specific procedure, yet so very fundamental in a lot of things we do.

vyn_halcyon

  • Playmaker Newbie
  • *
  • Posts: 9
Re: align object rotation to floor...using raycast normal? (SOLVED)
« Reply #4 on: May 02, 2016, 07:11:13 PM »
Problem:
Setting something to 0,1,0 on rotation makes it stand straight but turn 1 degrees to the left.

Normally not a big deal, but considering rotations do sometimes "interpolate along the scenic route" that 1 degree on the Y does kinda add up exponentially on each full orbit.

Is it even possible to store a raycast normal hit as a quaternion? if not, is it possible to convert a euler (i.e. RayCastNormalVariable) into a quaternion, without polarizing or ... disnullifying (totally made up that word just now) a set of Euler Vector3's? (I.e. 0,0,0 as opposed to 0,1,0)