Page 1 of 1

calculating vehicle from ground

Posted: Thu Aug 22, 2013 5:15 am
by vkreal
I am trying to figure best way to calculate distance between b2body(vehicle) and ground when off the ground moving at high velocity. Any thought you guys can throw my way?

Re: calculating vehicle from ground

Posted: Thu Aug 22, 2013 8:12 am
by iforce2d
Cast a ray directly downwards from the body position, would be the most typical way.

Re: calculating vehicle from ground

Posted: Thu Aug 22, 2013 2:59 pm
by vkreal
ray cast might cause performance problem(lower framerate) since i have to do it every step. My problem i am trying to solve is my vehicle traveling down hill at high velocity and catches some air. When this happens i would like to zoom back so the ground still shows in the view port.

Thanks!

Re: calculating vehicle from ground

Posted: Thu Aug 22, 2013 3:47 pm
by iforce2d
I really doubt a few raycasts each step will slow anything down.
http://www.youtube.com/watch?v=C-ScURIRTGA

In this game, I used 10 downward raycasts to sample an area in front of the rider, to help determine a good zoom distance, similar to what you are talking about. It's also used to set his head angle in a realistic manner:
http://www.youtube.com/watch?v=OL66G3JLYvA

Compared with all the other work that Box2D is doing every step, a raycast is almost nothing. Best way to find out is give it a try ;)

Re: calculating vehicle from ground

Posted: Thu Aug 22, 2013 6:04 pm
by vkreal
AWESOME! that''s what I am looking to achieve from your example game. I will give it a try.

Thanks for your help!

Re: calculating vehicle from ground

Posted: Mon Aug 26, 2013 2:10 am
by vkreal
I am curious why 10 downward raycasts to sample an area. why won't one straight down work? I am using one raycast straight down to sample distances to ground but i see the zooming kind of jerky. I think it might be results from the raycast sometimes not hitting target(not sure). I going to try more raycasts maybe that will solve jerky zoom problem.


Thanks!

Re: calculating vehicle from ground

Posted: Mon Aug 26, 2013 5:06 am
by iforce2d
More samples gives a better uh... sample of the ground. For example in the upper image here, one sample will result in a sudden change as the ray goes over the edge of the drop, even though the bike has only moved a tiny bit. In the lower image, one ray has dropped over the edge in exactly the same way, but the average height of the points has not changed so much.

Yes, more samples will probably fix it. I think I also changed the spacing between rays to sample a larger area ahead when moving faster.