Attention | Topic was automatically imported from the old Question2Answer platform. | |
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:
- What do the collision shapes look like for the characters?
- It appears that the characters get stuck on dead characters when they become elevated above the ground?
- Are you wanting the characters to climb on other characters or just pass through them?
- Are the rays ignoring the collision layer of the characters currently and only hitting the level layer?
- Look at the same scene, but with collision shapes turned on to see if anything pops out.
- 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
- 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…
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