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.addcentralforce(-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?