Raycasting

New releases and general discussions.

Post » Mon Nov 26, 2007 5:39 pm

Hello,
First thanks/congrats on a very nice app/engine thats easy to use and has flexible and powerful features.
I would love to see somekind of a raycast ability where objects can determine line of sight to other objects. This would really ease up the creation of a good AI.
B
1
G
5
Posts: 2
Reputation: 1,229

Post » Tue Nov 27, 2007 7:45 am

You might be able to do that with an instant-hit bullet. Just have your sentry (or whatever) fire an instant-hit bullet in front of him every cycle. If it hits the player, then your sentry "sees" him.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Nov 27, 2007 2:30 pm

But something like a Ray object would be very handy anyways. It could be used to make lighting effects too! And a bullet is never really accurate, since then number of directions is limited.
B
8
S
2
G
5
Posts: 744
Reputation: 3,288

Post » Tue Nov 27, 2007 3:47 pm

I don't think directs are a problem.

You would handle it this way:

Always
- Shoot bullet at player

if the bullet hits the player, he can be seen. If it hits a wall, then there's no line of sight.

I think it uses 360 degrees, with decimal precision, so it'll hit its target.

You can also layer the loops, so fire a detector to test if the player can be seen, then resize it to the size of the enemy and fire again - this time to test if the enemy will actually fit.

You can then set these as states:
CAN SEE PLAYER = YES
CAN WALK TO PLAYER = NO
-Then stay where you are and shoot

CAN SEE PLAYER = YES
CAN WALK TO PLAYER = YES
-Then run towards him and shoot

CAN SEE PLAYER = NO
-Wander aimlessly
B
4
S
1
G
5
Posts: 48
Reputation: 1,546

Post » Tue Nov 27, 2007 4:22 pm

mm.. guess it can be solved, even if it's going to be a whole bunch of bullets if you have a top-down shooter with 30 enemies and you want them to be vissible only if you can see them.

Still would be nice for lighing effects.
B
8
S
2
G
5
Posts: 744
Reputation: 3,288

Post » Tue Nov 27, 2007 4:50 pm

A while ago I asked if effects like this could be possible in construct, and was told they were. [url:2dpfsyio]http://www.gamedev.net/reference/articles/article2032.asp[/url:2dpfsyio]

That example was written in java, and the author says it would work with C++ as well.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Tue Nov 27, 2007 5:47 pm

yeah. that's what i'm looking for. I think someone made an example of this in mmf. I can't find it though.
B
8
S
2
G
5
Posts: 744
Reputation: 3,288

Post » Tue Nov 27, 2007 6:49 pm

I agree, some sort of line of sight function would be great. It'd be nice to set parameters for the line of sight on an object's properties, and then simply have an 'object can see [object]' event to run it all. Should save on memory usage too, when oposed to shooting out tons of invisible bullets for line of sight.

- Tom
B
2
S
1
G
5
Posts: 50
Reputation: 1,500

Post » Tue Nov 27, 2007 8:57 pm

In the meantime, there are ways to cut down on the processing.

You can test how close enemies are. For instance, if you have 100 enemies in the level, but only 10 are on screen, only run an LOS test on those 10.

Also, when doing an LOS test, you may use several detectors, but only do ONE test. So on each loop, you need to arrange the events so it moves all the detectors at once.

That'll cut it down a lot.
B
4
S
1
G
5
Posts: 48
Reputation: 1,546

Post » Tue Nov 27, 2007 9:59 pm

[quote="Dines":3d7xpkne]I think it uses 360 degrees, with decimal precision, so it'll hit its target.[/quote:3d7xpkne]

True, the bullet object uses 360 degree rotation. Anyone wanting to know more about the bullet movement should check out the Ghost Shooter tutorial... the monsters in that use bullet movement. Bullet movement can do a lot of stuff that doesn't actually have anything to do with bullets.

And I see you're using part of the clever pathfinding routine you posted on TDC :)


As for the memory usage, just have the bullets destroy themselves when out of the screen, or on contact with an obstacle or player. Instant hit means they'll be gone in just a couple of cycles.

I don't see how the memory usage would be all that much higher than a raycaster updating every cycle for every sentry on the screen. It would be pretty negligible. And creating a line-of-sight routine with the bullet only constitutes coding a few events, as Dines showed. If there were a dedicated raycasting object, you'd still be creating at least three events with it (shoot ray, does the ray hit, does the ray not hit), so you'd only be cutting down your events by a small handful when making a line-of-sight routine. I just don't see how cutting out that handful of events would warrant the time it would take to develop a whole new object. An object should make the event coding process easier by replacing large amounts of events, not small ones. But hey, the SDK is there for a reason, maybe someone could take a crack at it anyway.

As for lighting effects, yeah it would be pretty useful, depending on the scope of the object. It's a pretty big leap from casting a ray to rendering a shadow.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Next

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 0 guests