Battle Tank 2d tread rigid body logic

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By aadyainfotainment

Hi there,

I have been struggling to get the logging right for the 2d battle tank tracks(treads).

It’s a sideway tank and not topdown. similar to hills of steel.

I have created rigid bodies for wheels and the tank. As far as I do not add the treads to the wheels, they work fine. But when I add treads, they do not move the tank but keep moving and colliding with the treads instead.

For the treads I have used small rectangular rigid body.
connected them together with the pinjoint2d.

The player is a node2d
Connected the body(rigidbody2d) with the wheels using spring joint 2d.
the upper small wheels (rigidbody2d) connected to the body with pinjoint2d.

for keeping the bigwheels together I added a coupler(rigidbody2d) between two wheels.

my code added on the Player to move the wheels is as per below:

extends RigidBody2D

var wheels = []
var speed = 60000
var max_speed = 50

func _ready():
    wheels = get_tree().get_nodes_in_group("wheel")

func _physics_process(delta):
    if Input.is_action_pressed("ui_right"):
        for wheel in wheels:
            if wheel.angular_velocity < max_speed:
                wheel.apply_torque_impulse(speed * delta * 60)

    if Input.is_action_pressed("ui_left"):
        for wheel in wheels:
            if wheel.angular_velocity > -max_speed:
                wheel.apply_torque_impulse(-speed * delta * 60)