Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Smoothing out the ray tracing of a surface on a curve


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 ThePointingMan   Members   -  Reputation: 196

Like
0Likes
Like

Posted 13 October 2013 - 04:51 AM

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?



Sponsor:

#2 AllEightUp   Moderators   -  Reputation: 4325

Like
2Likes
Like

Posted 13 October 2013 - 09:11 AM

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.

#3 rumblesushi   Members   -  Reputation: 159

Like
2Likes
Like

Posted 13 October 2013 - 02:46 PM

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, 13 October 2013 - 02:48 PM.


#4 ThePointingMan   Members   -  Reputation: 196

Like
0Likes
Like

Posted 16 October 2013 - 05:14 PM

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, 16 October 2013 - 05:17 PM.


#5 rumblesushi   Members   -  Reputation: 159

Like
0Likes
Like

Posted 20 October 2013 - 11:53 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS