Godot Version
v4.1.3.stable.official [f06b6836a]
Question
Hi! Im working on a new Godot project and I am having an odd issue involving freezing a rigidbody through script and that working differently then it being frozen in the editor. When its frozen in the editor the joints work as expected but with the frozen rigidbody only affecting the other rigidboy. When frozen through code however it seems to just not work with the joint anymore and disconnects. Here is the code:
extends RigidBody2D
var speed = 40
@export var joiner: Node2D
var maxdist
@export var right = false
var Horiz = 0
var Vert = 0
var frozen = true
# Called when the node enters the scene tree for the first time.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _ready():
maxdist = global_position.distance_to(joiner.global_position) # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if(!frozen):
freeze = false
else:
freeze = true
#if(global_position.distance_to(joiner.global_position) > maxdist + 1):
# velocity *= 0
if(frozen):
if(right):
Horiz = Input.get_action_strength("Right") - Input.get_action_strength("Left")
Vert = Input.get_action_strength("Up") - Input.get_action_strength("Down")
else:
Horiz = (Input.get_action_strength("Right2") - Input.get_action_strength("Left2")) * -1
Vert = (Input.get_action_strength("Up2") - Input.get_action_strength("Down2")) * -1
position += Vector2(Horiz * speed * delta, Vert * -speed * delta)
print(position)
if(right):
if(Input.is_action_just_pressed("UnchainRight")):
frozen = !frozen
else:
if(Input.is_action_just_pressed("UnchainLef")):
frozen = !frozen