A character does not see behind obstacles

Started by beomoud, Fri 31/10/2008 12:29:54

Previous topic - Next topic

beomoud

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

beomoud

If anyone from here can't help me with this could a moderator move this post to the technical forum? Thanks...

Dualnames

Why not use pixel perfect collision module by SSH to your cause?
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ghost

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.

Khris

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

beomoud

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?

Khris

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.

beomoud

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

beomoud


SMF spam blocked by CleanTalk