L
L
Ler Den2019-04-11 17:27:28
Game development
Ler Den, 2019-04-11 17:27:28

What is the easiest way to glue a tank to the ground?

The tank in this case has a BoxCollider2D and a RigidBody2D with gravity.
The ground surface is an EdgeCollider2D with many vertices, so at any given time the tank touches ten vertices at the same time.
The goal is for the tank to be able to go up and down the slopes of the mountains, but at the same time not to roll over or move off the slopes while stationary. To prevent this from happening, by default I set the RigidBody2D material to Friction 100, which allows the tank to stand on a slope, and when the movement key is pressed, I change the material to Friction 0.4, which allows the tank to move.
And everything would be fine, only the tank still rolls over on steep slopes. As you can see in the picture, the nose of the tank is turned up.
5caf4d72ca08f941029713.png
and in order to avoid upheavals, it occurred to me only to repeat the effect of the caterpillar - i.e. so that the bottom of the tank repeats the relief of the earth's surface. During contact with the ground, you can try to read its coordinates and build an EdgeCollider2D with the same points, only on the tank. I don't know if it will help, but maybe there is a simpler way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2019-04-12
@rPman

Just an idea, make sure that the tank is not affected by physics in principle, i.e. process and draw it yourself. Calculate two points of touch of the tank with its bottom, respectively, when moving, move these points along the graph that makes the surface (recalculate the speed in x based on the angle of the tank), so your tank will turn. in moments when the second point cannot be found, you will have to decide what to do, either continue to move it, leaving the same angle, or make a turn in the direction of movement until there are two points of contact again. At a certain angle, stop (so that it doesn’t go vertically).
It will look almost natural, but you won’t have to do a SEA of unnecessary movements and calculations, especially if you want a lot of such tanks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question