Chasing AI
What are the problems with the current chasing AIs? They are very inaccurate, they do not have any speed limits (meaning the can go at the speed of light) and will get stuck in almost every edge. These things make the chasing pretty inaccurate.
I made a deep research over SMBX 1.3 and found that their chasing AIs are actually very interesting: when the NPC is under the player and it's horizontally close (A distance minor than 5 blocks) it will try to move away from the player until gains altitudes and stabilish itself in the process. I also could noticce that the acceleration is much more slower than in SMBX 1.4.4. Knowing this, I made a chasing AI which tries to be a recreation to SMBX 1.3's AI.
- Spoiler
- Red: original Chasing AI
Green: Custom AI
The code can explain the things better that I could, please give it a look:
- Spoiler
Code: Select all
with npc(sysval(param1))
'Speed limits
if .xsp => 3.2 then
.xsp = 3.2
elseif .xsp <= -3.2 then
.xsp = -3.2
elseif .ysp => 3.4 then
.ysp = 3.4
elseif .ysp <= -3.4 then
.ysp = -3.4
end if
'First frames control
.ivala = .ivala + 1
'Collision with Block
if .ysp = 0 and .ivala > 2 then
.ysp = -3.6
elseif .xsp = 0 and .ivala = 0 then
.xsp = 1
end if
'Horizontal movement
if char(1).x > .x - char(1).pwidth + 32 + 6 then
if .ivalc = 0 then
.xsp = .xsp + 0.048
end if
if .facing = 1 then
.facing = 0
end if
elseif char(1).x < .x + 32 - 6 then
if .ivalc = 0 then
.xsp = .xsp - 0.048
end if
if .facing = 0 then
.facing = 1
end if
end if
'Vertical movement (sighly different to the horizontal one)
if char(1).y > .y - char(1).pheight + 32 then
.ivalc = 0
.ysp = .ysp + 0.056
.ivalc = 0
elseif char(1).y < .y + char(1).pheight + 32*4 then
.ysp = .ysp - 0.036
'If the npc is under the player and it's close, it'll will try to move away. The ivalc control is to prevent two movements of x axis at the same time
if char(1).x > .x - char(1).pwidth - 32*4 + 32 and char(1).x < .x + 32*4 then
if .x > char(1).x then
.xsp = .xsp + 0.048
elseif .x < char(1).x then
.xsp = .xsp - 0.048
end if
.ivalc = 1
else
.ivalc = 0
end if
end if
end with
Here's the example level:
Another little suggestion:
I noticed that in SMBX 1.4 the Para-Goombas and Para-Koopas jumps actually a bit mor (in comparison to SMBX 1.3). I'd suggest add a jump of a Y speed of -8 instead of -9 which is the current one) in this way it would stand exact the same as SMBX 1.3.