- Home /
vehicle stops when colliding with ramp
I have a vehicle that floats above a terrain object and will "float" over various hills/bumps/etc. I would like to create a mesh for a ramp that the vehicle can hit to get launched into the air. the vehicle is using a capsule collider and the ramp is using a mesh collider. The ship will always come to a complete stop when colliding with the ramp instead of climbing the ramp and then flying into the air.
I also tried removing the mesh collider from the ramp and instead using rotated box colliders. The same thing happens in both instances. Any ideas?
EDIT here is the most important part of the flight script that controls how high the vehicle floats above the terrain
function FixedUpdate()
{
//other code for random stuff
transform.position = Vector3.Lerp(transform.position, new Vector3(transform.position.x, GetHoverHeight(), transform.position.z), hoverHeightStrictness);
//more code for more random stuff
}
function GetHoverHeight()
{
if( transform.position.y > Terrain.activeTerrain.SampleHeight(rigidbody.position) + (hoverHeight + buffer)) {
if(boosting){
floatHeight -= (gravity + boostGravityMultiplier);
}else {
floatHeight -= gravity;
}
return floatHeight;
//~ thrust = 0;
}
else if( transform.position.y < Terrain.activeTerrain.SampleHeight(rigidbody.position) ) {
floatHeight = Terrain.activeTerrain.SampleHeight(rigidbody.position) + (hoverHeight);
return floatHeight;
}
else if( transform.position.y < Terrain.activeTerrain.SampleHeight(rigidbody.position)+ (hoverHeight - buffer)){
floatHeight += climbSpeed;// Terrain.activeTerrain.SampleHeight(transform.position)+ hoverHeight;
return floatHeight;
//~ thrust = 0;
}
else {
floatHeight = (Terrain.activeTerrain.SampleHeight(rigidbody.position) + hoverHeight + buffer);
return floatHeight;
//~ thrust = 0;
}
return floatHeight;
}
the posted code only shows how i am using the "terrain.sampleHeight" to find the height of the terrain underneath my gameObject and then bump the GO up the desired float distance. Should I use raycast to detect other meshes to do the same thing?
Answer by Waz · Jul 12, 2011 at 11:17 PM
You are moving your ship by changing it's transform.position. That will defeat any physical interactions.
Whatever you do to make the ship go over ramps will work to also keep your ship floating above the terrain, and even let it "get air" off steep rises in the terrain.
For example, you can make a physical ship float just by having the collider somewhat below the ship's visual mesh.
So fix how you are floating, then you'll be able to get the ramps working.
Oh so what you are saying is that by setting the ship's float height explicitly, it is essentially "pulling" the ship down into the ramp. This causes the ship to just stop ins$$anonymous$$d of riding up to the ramp, correct?
Are you suggesting I have an empty game object with a collider attached to it that is offset to the float height, and then have a regular collider attached to the ship to catch crashes?
so i tried what you suggested and it did work, the ship will now ride up over any colliders. the problem now is that everything is too stiff, the ship feels like it is dragging something over the terrain (which it is). I need to figure out a way to make it feel like it is gliding over the surface.
The Physics$$anonymous$$aterial of the collider should be frictionless - so zero frictions and a Fiction Combine mode of $$anonymous$$inimum. Is that what you mean by "stiff"?
not exactly, what is happening is that i have a collider set beneath the ship to force it up into the air. That collider is dragging across the terrain and any other obstacle. Any time there is a bump in the terrain or anytime i go over an obstacle, the ship is jarred around. It is kind of like having shocks made out straight iron rods
Perhaps rather than having the visual ship as part of the RB, make it a separate object that you Lerp to the position of th RB.
Your answer
Follow this Question
Related Questions
Why vehicle decelerate on steerAngle 0 Answers
physics.OverlapSphere colliders 1 Answer
Car flipping and losing wheels on start 0 Answers
When player enters triggerzone call function 2 Answers
health depleat with colliders 2 Answers