Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: beomoud on Fri 31/10/2008 12:29:54

Title: A character does not see behind obstacles
Post by: beomoud on Fri 31/10/2008 12:29:54
This is challenging but i need to do it for my new rpg. What i want is find a way to check if a character sees another character or if he doesn't when he is standing behind a large obstacle.

I tried this but it didn't work, the idea is this:

Create a new object in the room, object 0, and have it use for grafic an empty sprite. I want to have it draw a new line on every game cycle on this sprite (with dynamic sprite maybe) and use this as the object's image. The line will start from the opponent's eyes and end at my player.

Now i want to check wether it collides with another object and check it's property: kind of object and if it is a large object have it know that they don't see each other.

I dodn't know if this is clear but that's the plan, i am also open to new ideas. It is a part of the detection system i have made for my rpg.

Thanks
Title: Re: A character does not see behind obstacles
Post by: beomoud on Sun 02/11/2008 19:42:55
If anyone from here can't help me with this could a moderator move this post to the technical forum? Thanks...
Title: Re: A character does not see behind obstacles
Post by: Dualnames on Sun 02/11/2008 22:09:52
Why not use pixel perfect collision module by SSH to your cause?
Title: Re: A character does not see behind obstacles
Post by: on Sun 02/11/2008 22:23:01
Depending on size and amount of obstacles, you could just script a function that checks a character's coordinates against any object coordinates.

When your player's x/y is either greater/smaller than
object.x-(object.width/2) or
object.x+(object.width/2) or
object.y-(object.height) or
object.y
then he/she will obviously be within an object's rectangle. If you only have one or two obstacles in, say. half your rooms, a generic function that takes a pointer to the objects sounds like a simple solution.
Title: Re: A character does not see behind obstacles
Post by: Khris on Sun 02/11/2008 23:43:33
You don't need an additional, invisible object; Object.GetAtScreen(x, y) should be sufficient for what you want to achieve.

I'd check three lines of sight: opponent's eyes to
-player's eyes
-player's feet
-in between (hip)

This can definitely be done but how depends on how you've structured the battlefield.
Are you using a standard 3rd person viewpoint and walkable areas etc.?
Title: Re: A character does not see behind obstacles
Post by: beomoud on Mon 03/11/2008 17:47:35
The thing is when i try to change the "line of sight" object's  graphic in repeatedly execute it turns into a blue cup. The dynamic sprites seem to depend on the Wait function in order to draw the line. As of where the line should be placed at i figured due to the perspective camera of the room that would mess things up we only need one line starting from the players feet to the enemy's feet and we need to check whether this line collisions with the "base" of an obstacle that is large enough to hide a character, i mean only it's projection to the ground.

The thing is the idea is good but how do i get it to work?

quote:"You don't need an additional, invisible object; Object.GetAtScreen(x, y) should be sufficient for what you want to achieve."

I know i don't need additional objects to display the obstacles that the objects in the room present. I need an additional object that would be the line of sight in order for me to check if it collides with the obstacles or not. Does anyone have any suggestions?
Title: Re: A character does not see behind obstacles
Post by: Khris on Mon 03/11/2008 17:55:23
Why do you need an object representing the line of sight? Firstly, you'd have to use pixel-perfect collision detection (which is pretty expensive) and secondly, going along the line, testing the objects found with Object.GetAtScreen(x, y) should suffice. I mean, why wouldn't it?

Regarding the blue cup issue: did you declare the DynamicSprite outside the function that's using it? If you didn't, it's deleted and recreated every function call.
Title: Re: A character does not see behind obstacles
Post by: beomoud on Mon 03/11/2008 23:33:38
No i didn't declare it outside or i did and i had problems working around that, anyway, i will try and see. I think though that even if the collision isn't pixel perfect that would do for me... thanks
Title: Re: A character does not see behind obstacles
Post by: beomoud on Tue 04/11/2008 13:29:39
Ok i did it and it looks great, thanks