[C2]Enemy: Line of Sight

Forum Home Forum Home > Construct 2 General > Your Creations
 Post Reply Post Reply Page  12>
Author
2,217 Rep
Post Options Post Options   Quote dcrew Quote  Post ReplyReply Direct Link To This Post Topic: [C2]Enemy: Line of Sight
    Posted: 07 Oct 2011 at 9:52pm
Hey, Dcrew here!

Just wanted to show off a creation here. (PM me if you wonder how it's done)



The line is always between the Player and Enemy (can have as many enemies as you want) and set's the line's width to the distance between the Player and Enemy and set's the angle towards the Player and it's position at the Enemy.

When the Line touches obstacles or walls or (anything you want really) it turns Red. thus meaning it cannot see you! But when it's green it can see you, thus making it aim at you and see-ing you!

I think this is a really good idea for enemy AI in games and will go great with Pathfinding :D

Thanks!

Click here to Download the Source file (Main)

Click here to Download the Source file (Mirror)

Edited by Kyatric - 08 Oct 2011 at 1:41am
bool exCeption = true;

if (exCeption())
{
exCeption = false;
inCeption();
}

void inCeption()
{
if(!exCeption())
{
inCeption();
}
}
Back to Top

Moderator
28,650 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 07 Oct 2011 at 10:20pm
You should post the cap and/or exe.

Edit: I edited the topic name to state it is for C2.

Edited by Kyatric - 08 Oct 2011 at 1:42am
Back to Top
2,217 Rep
Post Options Post Options   Quote dcrew Quote  Post ReplyReply Direct Link To This Post Posted: 07 Oct 2011 at 10:45pm
Originally posted by Kyatric Kyatric wrote:

You should post the cap and/or exe.


Updated first post with download links!
Back to Top
3,634 Rep
Post Options Post Options   Quote plauk Quote  Post ReplyReply Direct Link To This Post Posted: 06 Nov 2011 at 12:21am
This is great, and would probably work with platform type environment with a little tweak... would it be simple to add restrictions to the angle the line is able to move? ie... restrict the enemy's field of view?

I'll try fiddling to see what can be done.
Back to Top
4,407 Rep
Post Options Post Options   Quote SullyTheStrange Quote  Post ReplyReply Direct Link To This Post Posted: 06 Nov 2011 at 12:34am
@plauk, it would probably be easier to add conditions to when you are seen rather than restrict the line's movement. I'm using a similar system for my game, and though I'm not up to that part yet, I've given it a lot of thought and that seems to be the way to go.
All's fair in love and war, kid.
Back to Top
2,217 Rep
Post Options Post Options   Quote dcrew Quote  Post ReplyReply Direct Link To This Post Posted: 06 Nov 2011 at 11:31pm
@plauk It would be super easy to do that. Just make it so the line will only go green (it can only spot player) if the distance between the two are below 400 (or w/e you want)
Back to Top
984 Rep
Post Options Post Options   Quote cs2curious Quote  Post ReplyReply Direct Link To This Post Posted: 26 Mar 2012 at 7:52pm
Your the man ^_^
Back to Top
794 Rep
Post Options Post Options   Quote mowgly Quote  Post ReplyReply Direct Link To This Post Posted: 20 Aug 2012 at 4:55am
wow very nice, i need this solution for my game. Thank yuo
Back to Top
2,340 Rep
Post Options Post Options   Quote krish Quote  Post ReplyReply Direct Link To This Post Posted: 16 Nov 2012 at 2:16am
@dcrew ..thanks for this man.

Improved parts of it and added range calculations and stuff.
Hope it helps someone looking for such

Tutorials - enemy-ai-for-range-of-fire-and-line-of-sight-top-down-player

Edited by krish - 10 Dec 2012 at 1:28pm
Have a Power-Up Day!
--
Krish
I lives in a cave nd writes me games - "Tank 'em Up" is coming soon!
I haz facebook.com/toonheart
Back to Top
2,217 Rep
Post Options Post Options   Quote dcrew Quote  Post ReplyReply Direct Link To This Post Posted: 03 Dec 2012 at 5:56pm
Thank you my friend.
bool exCeption = true;

if (exCeption())
{
exCeption = false;
inCeption();
}

void inCeption()
{
if(!exCeption())
{
inCeption();
}
}
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down