Velocity of body isn't what is set in code

Godot Version

Godot 4

Question

I have a script for a basic flappy-bird movement.
But even if I comment out the jump function and gravity function, the move_and_slide method still makes the bird go up

This is the relevant code:

func _physics_process(delta):
	if not is_on_floor():
		#velocity.y += gravity * delta
		pass
      if Input.is_action_just_pressed("jump"):
		jump()
      move_and_slide()
func jump():
	#velocity.y = JUMP_VELOCITY
        pass

the real problem I think is that something else is changing the body’s velocity because when I print it to the console is like this (95.85297, -6.973267)

move_and_slide will update the velocity, this is affected by linear_damp etc.

So should I like set them to zero in _ready? I am in not changing those values so I really dont know why velocity should be affected

1 Like

Set them in the editor I’d say, but you also need to set the linear_damp_mode or it’ll override it with the global one, read more details there

Are you using a Character body or a Rigid body? Move and slide does not work on a rigid body and a character body does not have a way to set linear_damp

1 Like

My fault here, failed to mention flappy is a Characterbody 2D, so (I think? Just looking at the docs) it doesnt have linear_dump

also, dunno if is gonna help, if I change the motion mode to floating flappy only goes upwards, but if I change it to grounded it goes upwards and towards the left

You don’t need to do anything with the motion mode. I just tested the code you posted with jump and gravity commented out and it works as expected. The body does not move.

Unless I see your project, it’s diffusion to find the bug.

1 Like

Is there any way to send the project? (Also it takes my responses sooo long to get approved like whatttt)

This forum was under a quite heavy spam attack, so we now require posts of new users to be approved by staff. This changes automatically once you have interacted a bit with the community (and you reach trust level 1 because of that). I have set your trust level to 1 manually right now since you are clearly human :grin:

1 Like

Thank you so much :slight_smile:

in move_and_slide you forgot to write the “s”.

I cant find which move_and_slide you are refferring to, this one has the ‘s’

1 Like

oh, I’m sorry, you’re right, it seems that Google Translate played a trick on me. It’s spelled correctly without a translator.

1 Like

Ill try recoding the script from scratch but other than that I havent got any more ideas, maybe ill paste the scene in a new project and see if the issue persists

Have you found a solution yet?

I know what doesn’t work, the problem was in another script entirely, the problem is I dont really know why it doesn’t work.
Thank you all for your patience and sorry that I didnt really give the correct information :slight_smile:

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