playMaker

Author Topic: How to Rotate First Person with slope / floor  (Read 2092 times)

Orjax

  • Playmaker Newbie
  • *
  • Posts: 21
  • Father/son team, self taught, love learning
How to Rotate First Person with slope / floor
« on: May 20, 2017, 06:35:14 PM »
I am using a FPS from standard assets, I would like the whole character (controller, and camera)  to rotate with the floor.

Example I'm driving a car (first person) and want to go on vertical loop track, I want the FPS to go upside down,  Or a slope to rotate to look up the slope when on it.  The camera stays looking at horizon on any slope now, dont want that.

I want the camera Parallel to the ground that it is on.  Also having trouble getting it to go up a ramp with a 90 deg end angle,  A smooth ramp that ends in about 90 deg. angle.  I want it to fly straight up like a half pipe.   I have messed with all the settings in FPS and character. (and searched online for a couple hours)

Sorry hope that is not confussing.  Thanks for the help

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: How to Rotate First Person with slope / floor
« Reply #1 on: May 30, 2017, 01:55:42 AM »
I am less familiar with that character controller, but maybe you need a different character/camera controller?

Orjax

  • Playmaker Newbie
  • *
  • Posts: 21
  • Father/son team, self taught, love learning
Re: How to Rotate First Person with slope / floor
« Reply #2 on: May 30, 2017, 02:12:10 AM »
thanks for the reply,  I saw a free asset for car controller.  I'm gonna try that,

I just thought there was an easy setting to keep parallel to the ground you are on...
But I guess not, I will keep looking, maybe SPB vehicle physics asset will work...

Thanks,
Anthony

Doh

  • Full Member
  • ***
  • Posts: 124
Re: How to Rotate First Person with slope / floor
« Reply #3 on: June 01, 2017, 07:32:37 AM »
I can't explain this in a detailed way due to my lack of experience with this particular use, though character controllers I've played around with in the past used this method.

You can use the Raycast action to fire a ray from a gameobject, set it to store the "hit normal" as a variable, then use that variable to calculate how your character should be rotated to remain planted flat onto a surface.

Using only 1 ray can cause issues when the raycast slips between the point where two colliders meet, to mitigate this and increase the stability of the character you can increase the amount of rays (I've seen 3 and 4 used to good effect) and position them according to your specific use, that may likely be considered as four corners of a square. You'd then have to get the average of those vectors to use as your character's rotation.

Lerping the rotation should help smooth out jerkiness too.

Sorry if my wording makes little to no sense!

Orjax

  • Playmaker Newbie
  • *
  • Posts: 21
  • Father/son team, self taught, love learning
Re: How to Rotate First Person with slope / floor
« Reply #4 on: June 04, 2017, 12:43:50 PM »
Thanks Doh, That makes sense.  I just thought it was a common thing, so I thought there would be a package from ecosystem or a setting in inspector,  (align rotation with floor, or normals, or something)  But if I have to do a few raycasts, then I can probably use force in order to go up gradual 90 deg jumps, (like  a half pipe)
Gonna have to play around a bunch I guess.