Jump to content
  • Advertisement
Sign in to follow this  
ThePointingMan

Smoothing out the ray tracing of a surface on a curve

This topic is 2102 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Guest Hiwas
My suggestion for this sort of problem would be to run multiple update steps in order to break up the path into smaller pieces. Depending on how you are doing the computations, I'd probably look at the starting position and the ending position and checking if the distance to the track and orientation are too "different". If they are, back up half delta and check there, if half delta is not too different, compute that and recompute the end point based on the new intermediate point which should have less of a delta to the end point now. This assumes you are not completely reliant on a physics engine doing all the work and that you can break up the steps a bit more. If you are reliant on a physics engine, you could consider turning off collision between the track and the car given that the car is a "hover" car which sounds like it should never actually collide at all.

Another possibility with the physics engine is to use a ray cast prior to stepping where you figure out the normal at the end position before stepping the physics. Now impart rotational velocity so that over the physics update the ship will automatically rotate to the end orientation such that the car will not be purely purely linear motion straight forward. This would keep the nose from going straight into the road though it still would not solve for the car actually moving fast enough to penetrate.

There are a lot of possibilities ranging from the multiple stepping solutions (probably your best bets) to working around the linear time steps in the physics engine (probably not as good). The thing I see with the physics solutions though is that while you can probably get the rotational velocities to mostly work, it would leave speed control as a function of gameplay such that it works kinda like a slot car track, going too fast and you wipe out, going too slow and you won't make the loop etc.

Some more information on the setup of the code would be most useful to dig into the details better. I.e. which physics engine, if you have an actual curve description you can analyse pre-physics, etc.

Share this post


Link to post
Share on other sites

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?

Edited by rumblesushi

Share this post


Link to post
Share on other sites

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.

Edited by ThePointingMan

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!