0 votes

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)
Godot version 3.4.1
in Engine by (87 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.