Anyone want to advise on my Lemming's type NPC code?

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

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

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.

2D||!2D | 2018-05-10 23:58

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

Robster | 2018-05-11 00:03

My comment got submitted on accident so it wasn’t there yet…:stuck_out_tongue_winking_eye:

2D||!2D | 2018-05-11 00:12

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

2D||!2D | 2018-05-11 00:49

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

Robster | 2018-05-11 01:23

:bust_in_silhouette: Reply From: Robster

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

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

2D||!2D | 2018-05-11 14:44