Rigidbody2D won't move when Area2D is a child

Godot Version

4.2.1

Question

I’m having problems with moving my rigidBody2D. It used to work fine until I added an Area2d as a child. I’ve read about this issue before but I can’t seem to wrap my head around it and fix it into my own code. I am a beginner at Godot.

Code

extends RigidBody2D


#██████╗░██╗░░░░░░█████╗░██╗░░░██╗███████╗██████╗░  ░░███╗░░  ░█████╗░░█████╗░██████╗░███████╗
#██╔══██╗██║░░░░░██╔══██╗╚██╗░██╔╝██╔════╝██╔══██╗  ░████║░░  ██╔══██╗██╔══██╗██╔══██╗██╔════╝
#██████╔╝██║░░░░░███████║░╚████╔╝░█████╗░░██████╔╝  ██╔██║░░  ██║░░╚═╝██║░░██║██║░░██║█████╗░░
#██╔═══╝░██║░░░░░██╔══██║░░╚██╔╝░░██╔══╝░░██╔══██╗  ╚═╝██║░░  ██║░░██╗██║░░██║██║░░██║██╔══╝░░
#██║░░░░░███████╗██║░░██║░░░██║░░░███████╗██║░░██║  ███████╗  ╚█████╔╝╚█████╔╝██████╔╝███████╗
#╚═╝░░░░░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚══════╝╚═╝░░╚═╝  ╚══════╝  ░╚════╝░░╚════╝░╚═════╝░╚══════╝

var lock_position = null
var start_position = Vector2(0,0)


func _ready():
	lock_position = start_position.x

func _process(delta):
	#keys vars
	var inputUPp1 = Input.get_action_strength("upP1")
	var inputDOWNp1 = Input.get_action_strength("downP1")
	
	#movement
	apply_central_force(inputUPp1 * Vector2.UP * 45000000.00 * delta)
	apply_central_force(inputDOWNp1 * Vector2.DOWN * 45000000.00 * delta)
	position.x = lock_position
	


func _on_area_2d_area_entered(area):
	Global.shake = true

image

change to
func _physics_process(delta):

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.