![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Baolnar |
Hi everyone. I recently started using Godot to make my first game which is a 3D role playing game using mouse click to move.
I used the Navmesh template provided and imported my own models and attempted to replace the set_transform() function to use move_and_slide on my KinematicBody Character Node.
I have the character following the path but the movement speed is uneven. Between some points, the character moves slowly, between other points he zooms past really quickly. I think this may be because there are more points between some sections and fewer in other sections.
I’m looking to see if there is a better way to accomplish this. In fact I almost certain there is and could use some guidance. For example, I am checking if the character is close to his next point before removing the point from the array and getting the next point.
Here is a snip of my character nodes script that is handling the movement:
func _set_path(p):
path = p
set_physics_process(true)
func _physics_process(delta):
var direction = Vector3(0,0,0)
if(path.size() > 0):
var next_position = path[path.size()-1]
direction = next_position - translation;
direction.normalized()
look_at(next_position + Vector3(direction.x,0,direction.z),Vector3(0,1,0))
move_and_slide(direction * SPEED, Vector3(0,1,0),0.05,4,1)
if(abs(translation.x - next_position.x) <= 0.05 and abs(translation.z - next_position.z) <= 0.05):
path.remove(path.size() - 1)
var anim = get_node("Character/AnimationPlayer")
if(anim.is_playing() and anim.assigned_animation != "Anim_Run-loop"):
anim.stop()
anim.play("Anim_Run-loop")
else:
set_physics_process(false)