Advertisement

Smoothing out the ray tracing of a surface on a curve

Started by October 13, 2013 10:51 AM
3 comments, last by rumblesushi 11 years, 4 months ago

I've been using unity for some school projects recently, and I made a racing game fairly similar to F-zero GX. It was really unpolished though, and I've got a question about one thing that I thought really needed polish. While the hover car goes along the track, it shoots a ray directly below it and orientates itself so that the car's up is the same as the surface's normal. Gravity is always pulling in the hover cars down direction. The biggest problem I am having with doing this is that with upward curves. Lets say I was doing a loop de loop. The car would move forward by an amount, then orientate itself and move forward again. If you are going fast enough though, you end up moving so far forward that you tap the surface of the loop de loops curve with your ship, making you loose all momentum. Does anyone have any ideas as to what I could do to work around this?

Am I correct in thinking the ship is not orienting fast enough to the track? IE the the ship eases to its next target orientation, and if the ship is blazing past a load of polys with radically different normals, it doesn't adopt its orientation fast enough?

If you are relying on a physics engine and you can't simply increase how fast the ship orients to the normals, there's a few things you could do.

First, increasing the polycount of the collision geometry would help, so would casting a ray from the ship's nose rather than centre point. If those don't work, you could setup a dummy model that is positioned a % of your speed ahead of you on the spline, that governs your ship's orientation. For example if you were going 50mph it would be only half a ship ahead, and if you were going 500mph it would be 5 ships ahead. Then simply copy the dummy model's orientation matrix to the actual player ship.

By the way, how are you handling the hover mechanic?

Advertisement

For the hover mechanic, I shoot a raycast straight down from the center of the ship, if the distance from the start of the ray to where the ray hits is shorter then a specific amount it moves it back up to the minimum distance. As for the physics engine, It seems as though Unity uses the PhysX engine. Unfortunately I can't give you specific pieces of code right now as I am not at my house, but when I return there I will put up some more info on how I am doing everything. I think this first suggestion AllEightUp gave will probably do the trick though! Thanks very much for your input. I'm also thinking of doing something like what rumblesushi suggested, I'm thinking having a raycast at the middle, nose, and back, all checking would probably be best.

As it happens I use 4 rays to orient my ship to the track. One at the nose and tail to calculate the pitch, and one at either side of the middle of the ship to calculate the roll.

The orientation behaviour is generally perfect, the only problem I've found is not orienting all the way round an F-Zero style tube. You drop off at the sides. I'll need the gravity to be the vector between the ship and the middle of the tube rather than the ship's Y Axis.

This topic is closed to new replies.

Advertisement