The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hello, i do have an kinematic body called "Enemy" that moves and slides toward the player, but only in z and x, i dont want him to "fly" towards the player, just to have some gravity to he stays on the ground, how can i do this? thanks for any help.

Godot version 3.3.2
in Engine by (37 points)

2 Answers

0 votes

Have you tried adding something like "-9.8" to the "Y" component of the Enemy KinematicBody? Maybe add it in the _physics_process()?

by (3,164 points)

I tryed doing it, but it gets stuck and moves rarely, im using a flat terrain, do you know why this happens? thanks

Could you post the code used to move the Enemy node? BTW, to post code here, use the button above the text field for code.

there is the code, i used daniel buckley tutorial,
func _physics_process(delta): if is_on_floor(): gravity = 0 else: gravity = -0.98 if Input.is_action_pressed("shift"): moveSpeed = 16 if Input.is_action_just_released("shift"): moveSpeed = 10 if translation.distance_to(player.translation) <= attackRange and alerta<10: var dir = (player.translation - translation).normalized() dir.y = gravity move_and_slide(dir * moveSpeed, Vector3.UP) if alerta >= 10: var dir = (player.translation - translation).normalized() dir.y = gravity move_and_slide(dir * moveSpeed, Vector3.UP)
Shift is to increase speed when player is running, and alerta is for when he gets shoot no matter the distance to player, he starts chasing him. I tryed to add the if is_on_floor but as i said it keeps moving rarely and gets stuck.

From what I can tell, you should continuously apply the gravity, not just when the Enemy is on the floor (is_on_floor() can be spotty and unusable on some surfaces).

the problem could be with the collision shape, if it's not a capsule, make it one

ohhh yeah, that was the problem, much thanks for all the help, it was a sphere collision shape before, thanks

0 votes

instead of an kinematicbody, you can use an riggidbody.
a riggidbody already has all physiks

by (224 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.