playMaker

Author Topic: Vectors, Angles, Floats and AddForce multipliers  (Read 2303 times)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Vectors, Angles, Floats and AddForce multipliers
« on: April 09, 2013, 06:13:05 PM »
http://dl.dropbox.com/u/38606641/Heli/build.html

W - increase rotor speed (up)
S - decrease
A - Roll left
D - Roll right

Mouse - Pitch and yaw (point and aim)



So I'm working on this helicopter build and it was quite simple up til polishing. The problem is that I'm adding force on the Y axis as a spinning rotor should but helicopters alter the angle of their propellers to create attack against the air and pull them in a certain direction. Clearly that is too complex to add.

So what I'm wanting to do is take what I currently have and add a fake force in the direction you are flying. So if you roll right and tilt forward it grabs the two rotational values and multiplies them into the force additive in direction that you are already moving. I want to amplify what I currently have without adding force on the rotor (y, which is up).

It's kind of obvious once you play that you have to tilt 90 degrees to move forward because force is only added from the rotor on Y (self).

So, suggestions on how to do that? Getting the direction and adding some fake force into it. It can be per frame because I want it to grow and hit the clamp, then stop at a maximum like everything else.


I'm basically translating a scripted example, but I do not want to approach it the same way he has and I want to use different controls so I think the math is going to be different.

My approach is more "real" I think, and easy to create in playmaker but hits a wall on realism without this extra math and angle calculations.

Code: [Select]
var controlTorque : Vector3 = Vector3(
Input.GetAxis( "Vertical" ) * forward_Rotor_Torque_Multiplier,
1.0,
-Input.GetAxis( "Horizontal2" ) * sideways_Rotor_Torque_Multiplier
);

This is the major difference I can't seem to translate into Playmaker.

Quote
While this may seem confusing, it is really rather simple. The control input torque
vector is equal to the input axes multiplied by the control sensitivity. The reason the Y
value is set to 1.0, is because we want to simulate the torque on the body created by
the spinning of the rotors. This is the easiest way to apply that force without adding too
much extra code.
Now if the main rotor is active, then we wish to apply the net torque to the helicopter
body as well as the lift force created by the spinning rotors, so we simply write...

Code: [Select]
if ( main_Rotor_Active == true ) {
torqueValue += (controlTorque * max_Rotor_Force * rotor_Velocity);
rigidbody.AddRelativeForce( Vector3.up * max_Rotor_Force * rotor_Velocity );
}

So thats that, any help would be great. I'm in the dark with these vectors combined with math.
« Last Edit: April 10, 2013, 04:18:25 AM by Lane »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: Vectors, Angles, Floats and AddForce multipliers
« Reply #1 on: April 10, 2013, 08:17:56 AM »
fixed the webplayer link

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14692
  • Official Playmaker Support
    • View Profile
Re: Vectors, Angles, Floats and AddForce multipliers
« Reply #2 on: April 10, 2013, 11:29:27 PM »
Hi,

 where exactly do you have difficulties implemet this code in playmaker?

I can see one possible places where you can be in trouble tho:

Vector3.Up: do you know how to get this in playmaker?

ther rest is simple I would say, the trick is to create a fsm float variable acting as a "repository", you then multiply it again and again with the various values, and then set the torque value.

as for the +=, same, have a fsm responsible for holding the delat value, then add it to the torque value when it's all computed.

bye,

 Jean

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: Vectors, Angles, Floats and AddForce multipliers
« Reply #3 on: April 11, 2013, 05:17:23 AM »
I'll try to be more specific and not ramble.

He is using the Vertical and Horizontal Input preferences to add the torque, I want this controlled by the mouse instead of keyboard input. How does that work when getting an axis? I don't understand the axis and vector relationship.

From what I can see I need to get a vector for it to apply force, this should be the direction of travel which is derived from the rotation of the vessel * the control sensitivity. That makes sense, but I can't figure out how to get the rotations properly and fill the vector3. The rotation numbers are returned from 0 to 360 instead of positive and negative numbers that I could use as a multiplier. Is Axis different?

In my webdemo I basically have the motors working but I need to simulate the attack from the propellers so that you don't have to turn 90 degrees down to make it pull you in a direction fully (I'm only adding force to Y self, currently). I'm guessing that will be done with the above formula of translating the combined axes into a vector3 and pushing force to that direction - which I can't figure out.

Will GetAxisVector work for this or am I looking in the wrong direction? I think I'm just confused because I don't understand the difference between Axis, Vector and Rotation and that's making this code stump me.

Thanks Jean.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14692
  • Official Playmaker Support
    • View Profile
Re: Vectors, Angles, Floats and AddForce multipliers
« Reply #4 on: April 15, 2013, 12:18:29 AM »
Hi,

 the axis are expressed from -1 to 1 and are simply stored in a Vector2 or vector3 for convenience.

 the x component of the vector is the horizontal axis input value and the y component of the vector is the vertical axis input value.

 does that make more sense?
GetAxisVector is one way, you can also simply store each axis in a flot variable and then compose them where appropriate when you want to compute a force before applying the force

bye,

 Jean