• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Determining Line of Sight in AS3 using collision detection, need help!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1raimondi1337  Members

Posted 22 December 2012 - 09:03 PM

So I'm working on a project with a good friend of mine for our Programming IV class. We have all quarter to complete a project of out choice. We chose to make an arcade style survival game. Basically we want randomely generated rooms, Halo style weapons pickups and quake style power ups all with the goal of obtaining a high score, that we will record into a database and send to a web site.

We're on Christmas break for the next two weeks. We decided he was going to write the code for the room generation, and I was going to get a basi enemy AI done by the time we get back. I've been doing alright so far but I didn't consider everything else I would have to put in place to get this working
.

I generated a few NPC's on screen, a player, and a wall, and wrote the movement code for the player, now I want to have the NPC's move to the player, but only if they have a line of sight to him.

I'm thinking drawing an actual line between the two, and then doing a collision test on the line and the wall (which will eventually be an array of walls) is the easiest way. The hitTest function of AS3 uses the whole bounding box of the line, so it's useless. I found a method of using bitmap data to text each individual pixel, but its confusing me pretty well and I can't imagine it's very efficient.

Does anyone know the easiest way to determine collisions in AS3 or even an easier way to determine line of sight?

Project here if you want to look at it (the code is for the bitmap method and is buggy):

This is the Bitmap method I was trying to implement:
http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/

### #2Kaze  Members

Posted 22 December 2012 - 09:13 PM

The easiest way it to use a box2d port

http://www.sideroller.com/wck/

The built in flash collision functions are limited and ineffcent

Edited by Kaze, 22 December 2012 - 09:14 PM.

### #3raimondi1337  Members

Posted 22 December 2012 - 10:40 PM

The easiest way it to use a box2d port

http://www.sideroller.com/wck/

The built in flash collision functions are limited and ineffcent

I don't think our grade would negetively be effected by using an API, but I don't think that's what our teacher had in mind when he approved our project. I'd prefer to stick to writing everything from scratch.

### #4eppo  Members

Posted 23 December 2012 - 11:28 AM

Ray tests would be simple if you could express a wall as a set of half-spaces (forming a convex bounding volume), like a k-DOP (2-DOP in your case).

### #5raimondi1337  Members

Posted 23 December 2012 - 05:50 PM

I don't know what any of this means.

### #6Morphex  Members

Posted 23 December 2012 - 06:40 PM

Well, try and implement Separation Axis Algorithm  its very easy, and You can ray trace which is what you want. (There are a lot of Tutorials on SAT). I am not very familiar with flash, so I can't help you much further, but the SAT algorithm will help you in long term believe me.

Check out my new blog: Morphexe

### #7raimondi1337  Members

Posted 23 December 2012 - 06:45 PM

Well, try and implement Separation Axis Algorithm  its very easy, and You can ray trace which is what you want. (There are a lot of Tutorials on SAT). I am not very familiar with flash, so I can't help you much further, but the SAT algorithm will help you in long term believe me.

I'll look this up, thanks.

### #8odrega  Members

Posted 23 December 2012 - 08:49 PM

It's not very efficient, but something like this could work, if actual trigonometric calculations are thrown at it.

//Ray Trace - for loop
for(var i = 0; i < rayIterations; i++){

rectangle = new Rectangle(1, 1, ray.x, ray.y);
for(WallArray.length){
if(rectangle.hitTest(WallArray[whatever].rectangle)){
return true
}
}
}

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.