header general

Fly

  • Blue Shadow
  • Blue Shadow's Avatar
  • Administrator
  • Administrator
More
6 years 5 months ago #21 by Blue Shadow
Replied by Blue Shadow on topic Fly

doomedarchviledemon wrote: I thought it was working fine to just include it in the See state since it is in a loop state at that point. Even if it goes into the follow state it goes back to the See state, thus going through the whole code again and doing the A_Look in that sequence.

The issue with that is that the code would keep calling A_Look unnecessarily if a target was found.

To my understanding, a monster, or other actor that moves and interacts with the world, needs a Spawn and See state at minimum. Spawn meaning just to spawn the actor and See being used for everything else. Though now I see that is not necessarily the case in certain circumstances, in this case an actor that doesn't have any sort of attacks or other forms of interaction.

The thing about A_Look, A_Chase and the state sequences they're called from is that A_Look, upon finding a target, it jumps to the See state sequence where A_Chase is typically called. If at one point the target is lost, A_Chase jumps back to Spawn (or Idle if it exists), where A_Look, again, is typically called.

This fly actor may not be a typical monster, but it shares the whole look for target and chase target thing with them.

Either way, the See state has been removed and the code now only includes the Spawn and Follow state. From what I am seeing it is working properly.

I feel it'd be better not to go against the norm. So, in the Spawn state sequence, the fly looks for a target while in the See state sequence, it checks whether or not it's close to its target so it chases them by jumping to the Follow state sequence. And of course, in both of the state sequences the fly should wander and do the speed change thing.

Please Log in or Create an account to join the conversation.

  • doomedarchviledemon
  • doomedarchviledemon's Avatar Topic Author
  • Pain Elemental
  • Pain Elemental
More
6 years 4 months ago #22 by doomedarchviledemon
Replied by doomedarchviledemon on topic Fly
Phew... alright, let me see if I understand now.

Spawn:
FLYA AAABBB 1 A_Wander
TNT1 A 0
{
A_Look;

if (Random(0, 255) < 50)
{
A_SetSpeed(RandomPick(1, 3, 5));
}
}
loop
In this Spawn, the fly wanders like normal. It then Looks for a target, which if it does it will automatically go into See, otherwise it will go along and possibly change its speed and then loop back to repeat. But if the fly does see a target with the A_Look it will then...

See:
FLYA AAABBB 1 A_Wander
TNT1 A 0 A_JumpIfCloser(156,"Follow")
TNT1 A 0
{
if (Random(0, 255) < 50)
{
A_SetSpeed(RandomPick(1, 3, 5));
}
}
loop
Go here and continue wandering. But now it doesn't have A_Look because it doesn't need it because if it doesn't find a target it will automatically go back to Spawn after going through the rest of the code. All the while it looks to see if the target, that was acquired by the A_Look before, is within a certain range with the A_JumpIfCloser. If it doesn't see that the target is in range but is still Looking at the target then it will loop.


Follow:
FLYA AAABBBAAABBB 1 A_Chase
TNT1 A 0 A_JumpIfCloser(156,"Follow")
Goto Spawn
}
}
And then we have the follow where it actually does chase and then rechecks to see if the target is close. If so, it will loop, otherwise it will go back to Spawn.

Is this at least a little closer?

Please Log in or Create an account to join the conversation.

  • Blue Shadow
  • Blue Shadow's Avatar
  • Administrator
  • Administrator
More
6 years 1 month ago #23 by Blue Shadow
Replied by Blue Shadow on topic Fly

doomedarchviledemon wrote: Is this at least a little closer?

Yes, pretty much that, except for one thing:

But now it doesn't have A_Look because it doesn't need it because if it doesn't find a target it will automatically go back to Spawn after going through the rest of the code.

There's nothing in the See state sequence that'd make it go back to Spawn if the fly somehow lost its target while in that sequence. This means there's still a hole to plug in the code. Adding this line directly before A_JumpIfCloser should hopefully help:
Code:
TNT1 A 0 A_JumpIf(IsPointerEqual(AAPTR_TARGET, AAPTR_NULL), "Spawn")
It uses IsPointerEqual to compare the fly's target field to null. If it's null, then the target field doesn't reference any actor (i.e. there's no target, in this case), and so the code jumps back to Spawn.

Please Log in or Create an account to join the conversation.

  • doomedarchviledemon
  • doomedarchviledemon's Avatar Topic Author
  • Pain Elemental
  • Pain Elemental
More
5 years 6 months ago #24 by doomedarchviledemon
Replied by doomedarchviledemon on topic Fly
I understand this now, thank you for the helpful information. ^_^
This has now been update.

Please Log in or Create an account to join the conversation.

  • Blue Shadow
  • Blue Shadow's Avatar
  • Administrator
  • Administrator
More
5 years 5 months ago - 5 years 5 months ago #25 by Blue Shadow
Replied by Blue Shadow on topic Fly
Approved.

Edit: Added .
Last edit: 5 years 5 months ago by Blue Shadow.

Please Log in or Create an account to join the conversation.