Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: Slipstream vehicle physics?

  1. #1

    Default Slipstream vehicle physics?

    Just wondering how you guys set up the vehicle physics in Unity, did you use raycasting and spring joints?

  2. #2
    Join Date
    Apr 2010
    Posts
    1,529

    Default

    Simpler than springs. Just basically apply Newton's laws of motion.

    You know that for an object to stay in rest no forces can be applied on it: Fr=0 (being Fr the sum of all forces applied on the object).
    So here you have the gravity pulling down on the ship so you create a force that counters that gravitic pull, making your ship still in mid-air. Then you make that levitating force vary with the inverse of the ship's height above the ground (F=k/h in which F is the force that counters the gravity pull, k is a constant that works like a "bounce" factor and h is the raycast distance between the ship's geometric center and the track, measured perpendicular to the track's polygons) so that the ship maintains it's height after jumps and bumps.
    Last edited by Xpand; 3rd January 2013 at 01:07 PM.

  3. #3

    Default

    Thanks for the reply.

    Just trying to understand it.

    I've set the Rigidbody of the ship to 1000 and added a raycast downwards that stores the distance between the center of the ship & the track. I then have a bounce rate float of 600000 that is divided between the raycast distance, the results are then added as downward force from the ship.

    This gives a hover effect but doesn't seem to spring to a height above the track. I'm doing something wrong I imagine, but I don't know what.

  4. #4
    Join Date
    Apr 2010
    Posts
    1,529

    Default

    I guess you need some adjustments on having the floating force variate with the height. Does your ship drop below/ fly away from the normal floating height after jumps or bumps?

  5. #5

    Default

    It doesn't follow the slope of the track (just a plane with rotation on it for now) it just goes forwards and crashes in to the track.

  6. #6
    Join Date
    Apr 2010
    Posts
    1,529

    Default

    Are you sure you're measuring the raycast between the ship and the track? Because the force alone would be enough to keep your ship at the same height in every point of the track.

  7. #7

    Default

    Quote Originally Posted by Xpand View Post
    Are you sure you're measuring the raycast between the ship and the track? Because the force alone would be enough to keep your ship at the same height in every point of the track.
    Yes, however I'm not sure I'm doing the correct calculations with the results of the raycast.

  8. #8
    Join Date
    Apr 2010
    Posts
    1,529

    Default

    Try to normalize the raycast value by dividing it by a set height value.

    For example:
    Lets use the F=k/h formula:
    You want the ship to stay afloat at a height of 2 units, then you divide the raycast value (also measured in units) by those 2 units (h=raycast/2) so that the value of h, when the ship is at 2 units of height, is 1.
    When the h is 1 you want the ship to stay still, so you set the "k" to exactly the same value as the gravity pull force only with the opposite direction.
    Now you have a resultant force of 0 force units, which means that the ship has no acceleration on the vertical axis, so it still in that axis. It's called equilibrium.

    If the raycast value drops below 2 (when crossing bumps and ramps), the h becomes smaller than 1 and that increases the value of the lift force, since dividing a constant (k) by a number smaller than one will output a number larger than k. That increases the lift force and makes the ship accelerate upwards.

    If the raycast value is greater than 2 (i.e. after a jump), the outcome is the exact opposite of the last one and the ship suffers the effect of the gravitic pull.
    Last edited by Xpand; 3rd January 2013 at 04:10 PM.

  9. #9

    Default

    Thanks for the explanation, do I use an if statement for checking that h is 1?

    Also, what rigidbody value should I use?

  10. #10
    Join Date
    Apr 2010
    Posts
    1,529

    Default

    This system is totally analogic. You don't need logic tests like an if to make this work.

    The expression itself will adjust autonomously to the value of "h".

    well, if with rigidbody value you mean mass, I would start with 1 and then increase or decrease it until it looks right...

    I think the only thing it will affect is the floating height (the heavier the ship is, the lower it will float) and reaction speed (the lighter it is the faster it reacts to track irregularities).

  11. #11

    Default

    Hmm, then I'm doing something wrong (again)

    Here's what I have. I use playmaker but I'm sure you can see what I'm doing.

    https://www.dropbox.com/s/ap9ohrs6vo...ut%20Hover.jpg

    K is set to 9.81 as the gravity is -9.81.

  12. #12
    Join Date
    May 2012
    Location
    Adelaide, Australia
    Timezone
    GMT + 9.5
    PSN ID
    dreadofmondays
    Posts
    314

    Default

    Derkoi, you mentioned about the craft travelling forward into the terrain. There are two ways to combat this; the first is to have a number of raycasts at points around the ship, such as the front, back and sides; these will rotate the craft on the terrain.
    A more effective method that we use is to have a single raycast that returns the normal of the poly it hits and we then rotate the ship to match.

  13. #13

    Default

    Quote Originally Posted by dreadofmondays View Post
    Derkoi, you mentioned about the craft travelling forward into the terrain. There are two ways to combat this; the first is to have a number of raycasts at points around the ship, such as the front, back and sides; these will rotate the craft on the terrain.
    A more effective method that we use is to have a single raycast that returns the normal of the poly it hits and we then rotate the ship to match.
    Thanks, i'll look in to that once I get the main code working. I started the scene again using a primitives & right now it just flies straight up!
    Last edited by derkoi; 4th January 2013 at 07:56 AM.

  14. #14
    Join Date
    Jul 2010
    Location
    Somewhere in the center... Poland?
    PSN ID
    zero3growlithe
    Posts
    779

    Default

    Lol guys, don't want to be unpolite but well i guess i know the best how physics work in SSGX and i don't have to take guesses on how it really is xD It has nothing to do with physics laws or anything, the fact that "gravity speed" is 9,81 is just my approximation especially for game (if it would've been 9,81 for real then ship would almost not move xD) and it is u can say random.... almost, measured for eye Anyway, if u have any programming related questions u can contact me on Skype (same name as here: zero3growlithe)

    (me and my bossing around xd)

    EDIT: Also, keeping ship parallel to ground by rotationg it to ground's normal detected by ray is not the best solution if u want it to happen smoothly (i mean smooth rotation interpolation) as Quaternion.Lerp function will go crazy in some cases.... most cases and will interpolate rotation in not wanted way (in other direction than desired) so it is better to use rays. Still if u want the ship to bank like in WOHD while turning u will need to use external gameobject to have to independable rotations which u can edit as u need and have ship bank and be parallel to the ground (btw. i'm saying about rotation on z-axis (Vector3.forward))
    Last edited by zero3growlithe; 6th January 2013 at 07:42 PM.

  15. #15

    Default

    Thanks, i'll add you on skype. Also, you said about 9.81 being your approximation, well -9.81 is also Unity's default gravity anyways, that's where i got it from.

  16. #16
    Join Date
    May 2012
    Location
    Adelaide, Australia
    Timezone
    GMT + 9.5
    PSN ID
    dreadofmondays
    Posts
    314

    Default

    Earth's gravity is 9.81 m/s/s iirc. That's where the number comes from

  17. #17
    Join Date
    Feb 2002
    Location
    Toulouse, France
    Posts
    541

    Default

    Will every race take place on Earth ?

  18. #18
    Join Date
    Apr 2010
    Posts
    1,529

    Default

    Yup... Even the platformer events (which are inside a simulator) are going to use the same physics, probably a few changes in ship maneuverability, but we haven't really talked about that yet.

  19. #19
    Join Date
    Apr 2010
    Posts
    1,529

    Default

    I'm gonna use this thread to show off the first step on the creation of SSGX simulator engine:

    It's on a simple stage yet: the ship is only doing what can be considered as a keyframed animation, not simulating any physics.
    I also need to creage 3D file importer, namely OBJ importer, because the current ship is all "hand" modeled with no aid from a 3D software.

    I'll then make the physics simulation by calculating the ship's behaviour based on every possible component that contributes for the inner workings of a real ship.
    Example:
    Placement of levitating systems;
    Power of said systems;
    Airbrake efficiency from area, deployment angle;
    Engine efficiency based on used fuel and other intrinsic components;
    Position of RCS thrusters for standart ship maneuvering (airbrake-less turning, pitch up/down);
    Weight distribution;

    etc...

    I want to simulate body aerodynamics, but that's a bit too advanced for me at this moment, maybe in a far future!

    Seems like a fun project and it will help us to refine our physics too (inside the arcadey spirit, because no one wants a Wipeout Simulator 2014 )

  20. #20
    Join Date
    Apr 2010
    Posts
    1,529

    Default


    Simple particle physics applied to the ship: Lift force, weight, air drag, thrust, etc.
    Thrust is being controlled by the program. Ground bumps and such are made with mathematical 1D functions.

    Next step is to add rigid body behaviour, like following the curvature of the terrain, torque, etc..
    Last edited by Xpand; 19th February 2013 at 10:42 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •