0 votes

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))
Godot version 3.5b
in Engine by (91 points)

1 Answer

0 votes

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.

by (14 points)

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.

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.