Help with trembling kinematic body

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

Hi all

Hope someone can help me. I have a kinematic body that I want to move along a path. I can do it when it does not have a collision shape but as soon as I add a collision shape, it stays in the same place and trembles rather than moving. I am probably making a stupid mistake somewhere. I also asked in r/godot but didn’t get help. I will include some images and gifs to show what I mean by trembling!! It is fun watching but not what can use as an NPC behaviour.

Any help greatly appreciated.
Thanks

https://ibb.co/m8dK8qs

https://ibb.co/gZLpYKL

https://ibb.co/489qtfJ

https://ibb.co/F856qnF

Code below.

extends KinematicBody

var path = []
var pathind=0
const move_speed = 2
var dstat=0
var mtgt=null
var dirx=Vector3.ZERO

func _process(delta):
	if not mtgt and "chores" in get_parent():
		var rnum=int(rand_range(0,get_parent().chores.size()))
		print(get_parent().chores[rnum].name)
		mtgt=get_parent().chores[rnum]
		path=global.masternav.get_simple_path(global_transform.origin, mtgt.global_transform.origin,true)
		print(path, "to ",mtgt)
		pathind=0

	_follow_path()

func _follow_path():
	if pathind<path.size():
		dirx=path[pathind]-global_transform.origin
		if dirx.length()<0.5:
			pathind+=1
		else:
			_turn_towards(path[pathind])
			dirx=move_and_slide(dirx.normalized()*move_speed,Vector3.UP)
	else:
		mtgt=null


func _turn_towards(pos):
	var ldir=pos
	ldir.y=global_transform.origin.y
	look_at(ldir, Vector3(0,1,0))
:bust_in_silhouette: Reply From: TeaCrab131

Your kinematic body is probably already colliding with something as soon as you start the game. Check the spawn position, move the spawn point away from possible collisions and see what happens.

Sorry for the delay - life got in the way of coding!

You were absolutely right, the collision shape for the floor was too high. I feel so dumb right now!!

Thanks for the hint.

sxkod | 2022-08-24 15:49