Func _physics_process(delta): isn't running

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By undead_rat

I’m new to godot, so I really may of just made a dumb mistake, but func _physics_process(delta): isn’t running. It was yesterday, but after making some changes it’s stopped.

func _physics_process(delta):

print("Hello world")

velocity.x = 0
velocity.y = 0


if Input.is_action_pressed("move_left"):
	velocity.x -= speed * acceleration * delta
	sprite.flip_h = true
	
	
if Input.is_action_pressed("move_right"):
	velocity.x += speed * acceleration * delta
	sprite.flip_h = false
	
if Input.is_action_pressed("move_down"):
	velocity.y += speed * acceleration * delta
	
if Input.is_action_pressed("move_up"):
	velocity.y -= speed * acceleration * delta
	
	
velocity = move_and_slide(velocity, Vector2.UP)

Theres no output, including from “Hello world”, and the sprite is no longer moving. No errors are being thrown up by the debugger, so I’m not sure what the issue could be. Any ideas?

Please fix the formatting of your code for the forum. While it’s mostly right, the function name itself is misformatted.

jgodfrey | 2022-08-27 21:55

:bust_in_silhouette: Reply From: Ertain

Is this the contents of the _physics_process() function? BTW, may I suggest adding and subtracting “1” from the velocity variable, and not factoring in delta for the move_and_slide() function, as it already factors that in.

...
if Input.is_action_pressed("move_right"):
    velocity.x += 1
    sprite.flip_h = false

if Input.is_action_pressed("move_down"):
    velocity.y += 1
...

I am having the same issue. When the process below is written as “_process”, the script functions as intended, but when its “_physics_process” as shown below, the function does not even work.

func _physics_process(_delta: float) -> void: # gives gravity to "entities"
	var bodies = $Area2D.get_overlapping_bodies()
	var entities = []
	print("bodies")
	for body in bodies:
		if body is Entity:
			entities.push_back(body)
	
	for entity in entities:
		var distanceSquared = position.distance_squared_to(entity.position)
		var direction = entity.position - position

		var Fgrav = ((mass*entity.mass)/distanceSquared)*direction
		entity.apply_central_force(-Fgrav)