• 3D
  • Help with moving a Centipede, please..?

Good evening... Avowed beginner with Godot (but not with programming in general, nor game 'creation'...), I'm stumped with what I thought would be a fairly straightforward exercise. I have a 3D 'World' in which a First Person explorer can navigate. I would like to populate this World with animated 3D beasts; one example is this Centipede. I have collision detection in place, and can have the Beast follow an Animated path, but I have not found a way of having the creature move forward on its own. All I want, for now, is a few lines of code such that the Kinematic Body moves forward a few 'steps'; I'm thinking of having this triggered, for now at least, by the frame_counter. A Timer would be another, maybe better, option, but it's the movement I can't fathom. Here's a couple of screen shots, as illustration, of the environment and the code snippets I've been toying with...

I would beg patience; I've been looking at many sample codes and demos, and have perused this Forum in search of enlightenment, but in vain. I would especially appreciate replies in words of less than one syllable, such that a child of five could follow. I am wallowing in a quagmire of unfamiliar terms and notions; the words themselves I understand, but not the concepts they should portray. I'm hoping that this will improve as I further my experiments, but it's slow, so very, very slow. Thanks in advance, then, for any help offered; more information, if required, will be forthcoming to the best of my ability. Meanwhile... Keep well, stay safe. Douglas

There are few important basics you should be aware of: - ready() is a special function. Engine calls it only once immediately upon starting the game. It's useful for initialization. - process() is also a special function. Engine calls it every frame. This means it will be executed over and over 60 times per second. Its main purpose it to animate things. - move_and_slide() is the function that moves the KinematicBody. But it does so only for 1/60 of a second. It's meant to be called each frame for continuous motion.

Armed with the above knowledge we can rearrange your code a bit. Signal connections need to be done only once. They naturally belong into ready() which is called only once. The rest must execute each frame so it naturally belongs in process(). However, here we'll use physics_process(), a cousin of process() that ensures more stable timing, so our movement is smoother.

func _ready():
	hitbox.connect("body_entered", self, "on_hit_beast")

func _physics_process(delta):
	velocity = Vector3(0.0, 0.0, 1.0) * speed
	move_and_slide(velocity)

And that should nicely move our fellow centipede down the z axis.

@xyz said: There are few important basics you should be aware of:...

@xyz : Wonderful..! Many thanks; that's exactly the kind of information that's needed..! Quite some re-arranging to be done to clean up my scripts, in this new light, but I now have the creature gliding across the floor. Next step: count the steps, then find out how to synchronise a 'turn right' animation with a change of orientation, so that the 'z' axis pivots, before moving on. Baby steps, but that's a lot for a Centipede..! Onwards and Upwards; thanks again. Douglas

I'm sure you (and the centipede) will manage from here :)

@xyz : Indeed, although I've swapped the Centipede for a Roach, which has Left and Right Turn animations, missing from t'other. I found how to rotate the creature, and it's now marching around in a square, endlessly. A little clumsy, as code goes (understatement..!), but it's a working start from which to build. It doesn't take much, sometimes, to trigger that 'light-bulb' moment; would that there were more '101' examples with such useful snippets. Much more to do to get the whole Dungeon operational, and doubtless more (daft...) questions to come, though..! [Terminator] I'll be back... [/Terminator]

Douglas