Jump to content
  • Advertisement
Sign in to follow this  
raimondi1337

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

This topic is 2101 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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):

https://docs.google.com/open?id=0B6HdChtgXAsveWRRMWswb0NpQzAhttps://docs.google.com/open?id=0B6HdChtgXAsveWRRMWswb0NpQzA

 

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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
		}
	}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!