0 votes

Hi all,

I've had to have a break for a few months due to work etc but I'm back and into my latest game.

I'm trying to achieve a Lemmings type of NPC.

  • They walk well
  • They fall well
  • They climb well
  • The problem is, sometimes they go crazy. Images attached:

See the end of this short GIF to see the problem:

Link to GIF as I can not figure out how to embed it here sorry

and another GIF showing another example

The full code is below, the idea is this:

  • Kinematic2D Character
  • Forward raycast attached to check for walls / objects in front
  • Floor raycast attached to check for floor
  • They always try and walk right

Once alive and instanced:

WALK STATE

  • start walking
  • If floor ray contact, walk
  • ELSE, fall
  • If forward ray contact, climb

RUN STATE

  • start running
  • If floor ray contact, run
  • ELSE, fall
  • If forward ray contact, climb

FALL STATE

  • start falling
  • if floor ray contact, run
  • ELSE, fall

CLIMB STATE

  • start climbing
  • if forward ray contact, run

The code didn't show up here properly so have added a link to it here

Can anyone offer any advice as to why they're doing that? Thanks so much

in Engine by (810 points)
edited by

A few items:

  1. What do the collision shapes look like for the characters?
  2. It appears that the characters get stuck on dead characters when they become elevated above the ground?
  3. Are you wanting the characters to climb on other characters or just pass through them?
  4. Are the rays ignoring the collision layer of the characters currently and only hitting the level layer?
  5. Look at the same scene, but with collision shapes turned on to see if anything pops out.
  6. Change the auto spawn so that you can stop the characters after the first one gets stuck and then have a text box or debug box that prints the state that the character is in
  7. In that first GIF, what was that sparkle just before the region the soldiers get stuck? I only saw it that once and then they started getting stuck.

Thanks for the reply.

1: This shows the shapes clearly in blue:

2: You're correct on that. The image above should show the collision shape well though.

3: I want them to climb over anything in their path. Even vert (will work out anims for that later)

4: I'll investigate shortly, watch this space

5: I'll investigate shortly, watch this space

6: I'll have to do that later but will.

I apologise for 4 /5 /6 I Wasn't aware you had multi questions. I'll try these and report back. Thanks again, I really appreciate any help I can get on this

My comment got submitted on accident so it wasn't there yet..;P

just kind of thinking and typing here..

One thing I noticed is that just before the soldiers are getting stuck, they enter the falling animation and then continue to move in the x direction before going back into the walk/run state. Your code mentions you want them to just fall down or do you want horizontal movement still?

I also see this in both the climb and fall state.

soldat.motion.x +- 0

OK you found it!!

  • 4 Are the rays ignoring the collision layer of the characters currently and only hitting the level layer?

The dead soldier was on layer 1 and the live soldier was looking for layer 2. I put the dead on layer 1 and 2 and they're climbing over them!!!

Thank you so much, it's really appreciated.

RE: the falling, they are moving in x but I don't want them to. I'll dig into that shortly

1 Answer

0 votes
Best answer

Solved by /u/2D||!2D

The dead soldier was on layer 1 and the live soldier was looking for layer 2. I put the dead on layer 1 and 2 and they're climbing over them

by (810 points)

Congrats! Please update us on the forum with your project. Lemmings type games are always interesting =)

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 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 webmaster@godotengine.org with your username.

Categories