#GRAVITY NOT WORKING

12 messages · Page 1 of 1 (latest)

mild igloo
#

Im trying to apply gravity to an enemy in a 2d game as they are just floating around rn. Cant get it to work. I changed the node to a characterboddy2d node and copy pasted the var gravity and the if not isonfloor function to the enemy but it hasnt worked

timid comet
#

What is the value of gravity?

mild igloo
#

im not sure i dont see that. I dont have gravity defined as anything in the script that works either. Does the get.setting not get that?

timid comet
#

Try to print gravity in physics process and check.

#

Should be a valid value, but could be wrong.

mild igloo
#

its giving 980

spring lagoon
#

Neither the move_and_slide() or move_and_collide() functions is ever called within the physics process callback. Using one of these two methods is how you would normally use the CharacterBody2D to calculate velocity vectors and collisions to tell if it's on the floor. You also shouldn't change it's position directly as this will cause unintended results with the physics and collision detection.

timid comet
#

Of course; good catch @spring lagoon!

mild igloo
lusty scaffold
#

At the very end of your _physics_process(delta) function, add this (on its own line, and not under the velocity.y line):
move_and_slide()

#

And as burgundy said, you shouldn't modify the position directly, unless you're teleporting your character or something.
replace that last line's "position.x" with "velocity.x"

mild igloo