0 votes

So, the task seems pretty easy: create 2 RigidBodies2D and connect them, so, they'll move like tank caterpillars, that is, they should always have the same rotation and have the same distance between each other.

I tried 2 different joints: PinJoint2D and GroveJoint2D with length = 1. But all of them worked until first collision with something else: after collision the started to rotate independently.

The code is pretty simple:

extends Node2D...

func physicsprocess(delta):
left.addcentralforce(-left.appliedforce)
right.add
centralforce(-right.appliedforce) if Input.is_action_pressed("ui_right"): left.add_central_force(Vector2.UP.rotated(left.global_rotation) * force) if Input.is_action_pressed("ui_left"): right.add_central_force(Vector2.UP.rotated(right.global_rotation) * force)


(don't pay attention to missing underscores, idk why, but the website decided that I want to make text italic instead of putting the underscores)

extends RigidBody2D...

func _physics_process(delta):
    var rotated_velocity = self.linear_velocity.rotated(-self.global_rotation)
    var x_velocity = Vector2(rotated_velocity.x, 0).rotated(self.global_rotation).normalized()
    var y_velocity = Vector2(0, rotated_velocity.y).rotated(self.global_rotation).normalized()
    
    self.add_central_force(-self.weight * y_friction_coefficient * y_velocity)
    self.add_central_force(-self.weight * x_friction_coefficient * x_velocity)

What am I doing wrong?

Godot version 3.5.1
in Engine by (26 points)

1 Answer

0 votes

Hi,
Are you creating something that moves like tank caterpillars because that's what they are?
If so, maybe try KinematicBody where you control the movement.
What it sounds like is happening, is that the object hits another object and reacts in the way that it should. Physics is kicking in and moving the objects. The way a ball would or a spaceship in sapce.

by (2,053 points)

And... If I want to make, let's say, another tank somewhere and make pushable, then.. Will I need to simulate all of the physics in that case?

I think so, but the whole object could be made up of multiple sprites. So maybe that's the way to do it, if it's a tank and it needs to be rigidbody....

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 Frequently asked questions and 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 [email protected] with your username.