PDA

View Full Version : Slipstream vehicle physics?



derkoi
3rd January 2013, 11:19 AM
Just wondering how you guys set up the vehicle physics in Unity, did you use raycasting and spring joints?

Xpand
3rd January 2013, 12:55 PM
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.

derkoi
3rd January 2013, 02:32 PM
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.

Xpand
3rd January 2013, 02:52 PM
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?

derkoi
3rd January 2013, 03:00 PM
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. :|

Xpand
3rd January 2013, 03:21 PM
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.

derkoi
3rd January 2013, 03:38 PM
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.

Xpand
3rd January 2013, 04:05 PM
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 (http://www.physicsclassroom.com/class/vectors/u3l3c.cfm).

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.

derkoi
3rd January 2013, 07:21 PM
Thanks for the explanation, do I use an if statement for checking that h is 1?

Also, what rigidbody value should I use?

Xpand
3rd January 2013, 08:00 PM
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).

derkoi
3rd January 2013, 08:20 PM
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/ap9ohrs6vom3fs7/Wipeout%20Hover.jpg

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

dreadofmondays
3rd January 2013, 10:38 PM
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.

derkoi
4th January 2013, 07:53 AM
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!

zero3growlithe
6th January 2013, 07:30 PM
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 :g 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))

derkoi
7th January 2013, 12:36 PM
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. :)

dreadofmondays
7th January 2013, 11:41 PM
Earth's gravity is 9.81 m/s/s iirc. That's where the number comes from

vincoof
8th January 2013, 03:30 PM
Will every race take place on Earth ?

Xpand
8th January 2013, 04:23 PM
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.

Xpand
11th January 2013, 11:05 PM
I'm gonna use this thread to show off the first step on the creation of SSGX simulator engine:

http://www.youtube.com/watch?v=GQ_-0wSLnCU
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! :D

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 :g)

Xpand
19th February 2013, 10:30 PM
http://www.youtube.com/watch?v=1nc2oizbGec
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..

dropp
3rd May 2013, 01:21 PM
Just been playing the trial of slipstream gx - it's fantastic! How did you guys handle the collisions with the edges of the track to stop the ship flying off or getting stuck to the wall? And what type of collider / collider arrangement did you use?

dropp
3rd May 2013, 01:22 PM
Just been playing the trial of slipstream gx - it's fantastic! How did you guys handle the collisions with the edges of the track to stop the ship flying off or getting stuck to the wall and what type of collider / collider arrangement did you use?

docfo4r
3rd May 2013, 02:44 PM
Hey dropp. Thanks for your kind words.

For the tracks, we actually use two kinds of walls. The visible one which you can see with your eye and an invisible one, where you actually collide to. This way we can manipulate values of energy and speed taken only when colliding with a wall and even detecting how strong the impact was.
But for further questions about that subject you better ask/wait for zero3growlithe's answer since he is our coder and he set it all up. Meanwhile, enjoy the trial! Maybe you can share a gameplay video with us? We like to see how people are doing on the tracks :)

Panzerhandschuh
13th May 2013, 02:38 AM
I appreciate the info about how collisions work in your game, but I'm still not clear on how you override the collision impact forces. I PM'd zero3growlithe about it a few days ago but he didn't reply yet. Google doesn't seem to help me either with this particular issue so I'd appreciate it if you guys can give me a basic idea of how to change the collision behavior.

Frailavi
18th May 2013, 02:27 PM
Had the demo version sitting on my desktop for awhile, finally decided to give it a go. It was awesome, I'm very impressed with it so far and can't wait to see future versions. If there's anything you guys need help with from someone who doesn't know any kind of programming.

I'm a bit handy in php and javascript, as well as most things dealing with the adobe suite. AE and Premiere included. So if I can assist in anyway, let me know.