playMaker

Author Topic: Wheel colliders and math the target angle with logic  (Read 900 times)

Andrew_Thiago

  • Playmaker Newbie
  • *
  • Posts: 3
Wheel colliders and math the target angle with logic
« on: September 04, 2022, 12:07:47 PM »
Hi folks, how are you?  First of all, i'm sorry if it's too long to read, but i really can't make it short. I guess the context is important.

I'm a visual artist, so for me, to create all the things i've been doing in Playmaker using pure c++, would impossible. Playmaker is the best thing i ever found on internet till now. It make my dreams come true. So you can understand, i'm very bad with scripts, but i'm always trying to read something and trying to get something which i could translate to the Playmaker language and make use of it.
------------------------------

 I'm creating just for fun a crap game similar to Gta style. I have a test city and some test vehicles. One of those is a police car which must persuit a target while avoiding objects and another vehicles. For this to be possible, i'm using raycast. I also created 3 different FSM's: One controls the object avoiding, the second one deals with the target chase and the third one deals with the motor torque and brake torque.

If i'm avoiding an obstacle, the FSM that deals with looking at the target will be deactivated and vice-versa. The FSM that controls the speed is very useful, cause it will talk with both and will accelerate and break accordingly, doesn't matter which one of the fsm's is working at the moment.

The car uses wheel colliders, but to make it look at the target, i'm using the ''Rotate'' action, making the entire car rotate towards it instead, cause whe wheels will not behave the right way. If the vehicle is too far away from the target, the wheels will rotate + or - 90 degrees, making the it lock in place.
 To fix that, i check if the target angle is more than 90 degrees + or - from the vehicle angle using ''Get Signed Angle To Target''. Then if so, i check the distance from the target and then i make the wheels turn only some degrees to the right or left manually till it matches it's angle using float compare. But that's not realistic and right, cause as i have to set manual degrees to the wheels to turn, the car will move like a crazy sometimes, turning too much or too little towards the objective.

I know how to use the ''Clamp'' action, but i don't know where to use it in this situation you know.

Let me ask you some questions please:
-----------------------------------------

1- How i'm suppose to make the wheelcolliders angle match the target angle while respecting the max angle the wheels colliders can turn? 

2-
Which parameter should i get from the wheelcolliders to change it's angle? Cause i'm only using the ''Set Wheel Collider Steer Angle'' for now.

I know that in C++, to make the car wheels turn toward the target the way i want after making some calculations would be someting like:

....''private void LerpToSteerAngle() { wheelFL.steerAngle = Mathf.Lerp(wheelFL.steerAngle, targetSteerAngle, Time.deltaTime * turnSpeed);''

3 - How to translate that so i can make of it please?

Thank you so much for the attention and help. Anything will be very helpful. I'll put some prints below.