playMaker

Author Topic: Alligning Character Angle To Floor  (Read 1800 times)

Xinus22

  • Playmaker Newbie
  • *
  • Posts: 3
    • View Profile
Alligning Character Angle To Floor
« on: February 14, 2017, 11:47:06 AM »
Hello there!

I wanted to ask this because i was curious about this for a long time. How do i make that when my character stands on a ramp or something else that is not just a plain floor he changes his angle approtiately? Like in a 3d sonic game for example. i know that i need to use Raycast Store Hit Normal action but i can't get how do i need to use it exactly. if somebody know a solution for this he will be my life savior. well not really but still it will be very appreciated.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14501
  • Official Playmaker Support
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #1 on: February 15, 2017, 12:14:40 AM »
Hi,

what kind of character are you using, it's important because for example a third person character component will not allow you do to so.

 Bye,

 Jean

Xinus22

  • Playmaker Newbie
  • *
  • Posts: 3
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #2 on: February 15, 2017, 01:10:02 AM »
I am using character controller based on this tutorial It's really simple and easy to use. i just added vertical axis so player could walk in 3d space. i don't like the way he created jumps though.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14501
  • Official Playmaker Support
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #3 on: February 23, 2017, 01:37:58 AM »
Hi,

 ok, so I modified it, and yes, the jump will need to be done differently with likely proper raycasting ot something as is, the mods to follow ground corrupts the jumping and grounding behavior.

 I modified the "Movement" Fsm:

- I get the normal of a raycast hit going down in the world ( this will need to be checking for wether it hits a ground object or not, use layers or more complex fsm to do this)

- then I use the horyzontal axis within a crossProduct to get the up AND forward direction in one go (quite happy with this trick actually, else it's a nightmare to combine rotation of character and ground normal :) )

and that's it really. I keep the velocity as is without reflecting the angle of the character, I don't think you'll have ground at very high angles anyway, else you would then need to express velocity in local coordinate of your character

I have attached a modified scene taken from the tut you mentionned.

Let me know how it goes :)

Bye,

 Jean

Xinus22

  • Playmaker Newbie
  • *
  • Posts: 3
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #4 on: January 05, 2018, 12:13:05 PM »
Okay.. first sorry for such late respond i totally forgot about that i wrote that here. second thanks a lot! it works really well but i have a problem which i stumbled upon and have no idea what to do with it.

The problem is that i tried to adapt this for 3D space by adding the second axis. and i thought that it worked until this happened. when the player faces the slope he walks on his angle does not change(second picture). but when i try to go sideways it does (first picture). i tried some things to fix that but they didn't work. is there any way to fix that?
« Last Edit: January 07, 2018, 10:48:00 AM by Xinus22 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14501
  • Official Playmaker Support
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #5 on: January 18, 2018, 11:16:45 PM »
Hi,

 you'll need to fiddle a bit more with it, what do you want, that it follows angle or that it stays vertical?

 Bye,

 Jean

Stuard

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #6 on: April 01, 2018, 10:50:30 AM »
hey Guys,
i hop its not off Topic but i want to ask - ive created a non physical player controller for my game and get the normal of the terrain via raycast to align my character to the ground - quaternion up via [...] from rotation (0,1,0). It works perfectly when the player faces forward in world direction but i cant get my head around how to make it possible to rotate. Via the Rotate action and some fiddeling i get it to work but well the normal rotation doesnt work when the controller faces the 180° mark.

Greetings,
Stu

looks like in the attachment then - how can i get my character to rotate and keep the grounding corrrect?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14501
  • Official Playmaker Support
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #7 on: April 03, 2018, 03:42:30 AM »
Hi,

 did you try the package from earlier in that thread?

 Bye,

 Jean

Stuard

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #8 on: April 03, 2018, 05:07:19 AM »
Thanks for the reply Jean :),

I tried to install it but it won’t extract into my unity folder :/
I’m using unity 2017.3.1

-i correct myself, didnt get that it is a .scene  ::) Im going to look in this now  ;D

Greetings
Stu
« Last Edit: April 03, 2018, 09:10:18 AM by Stuard »

Stuard

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #9 on: April 03, 2018, 02:19:24 PM »
Hi :)

Sorry, but i dont realy get the setup in the previously posted scene (or it does not work correctly on my side (I don’t get ground allignment)?)  :-\
My FSM tree looks as follows and i dont realy now where i can add/multiply the forward direction (if i use a parent object).

Greetings,
Stu
« Last Edit: April 03, 2018, 11:53:30 PM by Stuard »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14501
  • Official Playmaker Support
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #10 on: April 04, 2018, 12:03:30 AM »
Hi,

 I see, you need to start again, with the minimal stuff. Make it align to the ground, once that works, make it rotate around itself based on inputs.

 Also, have you tried to separate your logic into several Fsms, this might help and have less crowded states with dozens of actions, it's never a good thing to have so many actions.

I would move and rotate on regular update and then another fsm would align to floor on late update.

Bye,

 Jean

Stuard

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #11 on: April 04, 2018, 12:48:02 AM »
Hello :),

Allright i have 3 FSM's so far, one for the animation controll, one to apply Rotation, Translation and the calculated ground alignment :). The last state is to grap the Ground angle and get a Quaternion which i calculate with the help of another post you replied to.

If i would reduce my game to a 2D sidescroller, the ground alignment would work perfectly.

The problem i would think about is, that i hard set the calculated ground alignment with set rotation (when i leave the smooth rotate to function aside) and the rotate function stands in conflict whith that so it wont rotate because i set the rotation also every frame :) - When i seperate (i tried that 2) The ground alignment to one object and apply the Translation and Rotation to a Parent it ends in the missalignment of my first post around the 180° mark

My first version also had just one raycast to get the normal without the averaging stuff but there where the same problem - It also makes no difference casting in world or self space :)

- Sperating final ground alignment and the Rotate action ends in a Front facing Jittering :/

https://drive.google.com/open?id=1-1MKEptck3nH8cc7wDktdWOZNoJP7UFB

Greetings,
Stu

Stuard

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #12 on: April 04, 2018, 09:07:40 AM »
Allright, i got it

i hope the picture below explains it. For short and a realy easy way; i align a parent to the ground wile rotation the child inside in self space. Then get the forward direction and translate the parent times the input speed via the translate action :)

Greetings,
Stu
« Last Edit: April 04, 2018, 09:42:32 AM by Stuard »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14501
  • Official Playmaker Support
    • View Profile
Re: Alligning Character Angle To Floor
« Reply #13 on: April 04, 2018, 11:46:22 PM »
Hi,

 Good, I am glad you sorted it out!

 Bye,

 Jean