Hello i need a bit of help

Godot Version

godot 4.2.2

Question

hello I’m doing an online course and i have to make this cylinder go up, left and right but it doesn’t move, i don’t know what i am doing wrong.

func _process(delta: float) -> void:
	if Input.is_action_pressed("ui_accept"):
		apply_central_force(basis.y * delta * 1000.0)
		
	if Input.is_action_pressed("ui_left"):
		apply_torque(Vector3(0.0, 0.0, 100.0 * delta))
		
		
	if Input.is_action_pressed("ui_right"):
		apply_torque(Vector3(0.0, 0.0, -100.0 * delta))
		
		```

Can you put this code in physics_process and not process? moving physics-bodies should always happen in physics_process

Also what is happening when you run the code?

1 Like

this is how the code is on the course, and it loads good but it dosent move

How does the scene look like?

i meant the scene-tree. Have you tried pressing “space” and your arrow keys?

yes i have
Captura de pantalla 2024-09-11 184848

Okay try the following code and check if its prints something when you click space or arrow keys:

func _process(delta: float) -> void:
	if Input.is_action_pressed("ui_accept"):
		print("Space")
		apply_central_force(basis.y * delta * 1000.0)
		
	if Input.is_action_pressed("ui_left"):
		print("Left")
		apply_torque(Vector3(0.0, 0.0, 100.0 * delta))
		
		
	if Input.is_action_pressed("ui_right"):
		print("Right")
		apply_torque(Vector3(0.0, 0.0, -100.0 * delta))

didnt work and it didnt print anything

Then go to your project settings and go to the inputmap. Either you are pressing the wrong buttons or the inputs are not defined

You can either create your own inputs or press on “show built-in actions” and then search for “ui_accept”

2 Likes

I’d say try first to use _physics_process() as @herrspaten suggested, and remove the delta multiplier, just to check if there’s any reaction at all. I recommend to remove delta because it is a very small number and the cylinder just seems to be not reacting.

That’s strange, what keys are you using? check the input map at the settings to see what keys are connected to actions “ui_right” “ui_left” “ui_accept”.

dose not work

Can you show the scene tree of the cylinder?

where do i do that?
Captura de pantalla 2024-09-11 185907

Just like you did here, get in the scene of the “player” and send the scene tree

no but the input map

Send the settings of the rigidbody. also, change the weight of the rigidbody to a lower weight and apply force regardless of input. remember to do that at _physics_process()

What about the input map?

how can i see it