Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / line of sight pls

Author
Message
steve c
21
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 19th Feb 2005 05:44
okay for my enemys line of site i am using a cone and positioning it at their head by using glue object to limb command but whenever i scale it to make it longer so they can see more it comes out the back of their head aswell and theirs no way i can move it because it is glued on is their another way i can do this pls

current projects
codename : tasgarad
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 19th Feb 2005 07:30 Edited at: 19th Feb 2005 07:38
Steve C,

I would suggest not using a cone for your enemy's line of sight. Instead, try using your angles and distances. Try these steps to make a boundary of sight for your a.i.

1.)Give your enemy a limit in how far away he can spot objects. To do this, measure the distance from the enemy to the player, or whatever he needs to spot, with this formula, distance# = sqrt((e_xpos - p_xpos)^2 + (e_zpos - p_zpos)^2). Where "e_xpos" is the enemy's position on the x coordinate, and "e_zpos" is the enemy's position on the z coordinate, and the "p" stands for player. To give the enemy a limit to how far he can see, just use the code
.

2.)Now, give it angle boundaries, because a person can only see so far to his left and right and up and down, until he turns his head or body. Use "atanfull()" to get the angle between the enemy and the player. Try this
. So, if the enemy's current angle of direction(from left to right) is 90, then the player would have to be between the angles of 45o and 135o for "withinbounds" to = 1.

Here is how I would write a simple 2D program of circles and lines, to get the enemy to chase the player, if within the view limits of the enemy.


This program might be a little buggy, as it was written without testing. If it is not working correctly, let me know and I will debug it. If you have specific questions, feel free to ask.

+NanoBrain+
hexGEAR
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Naytonia
Posted: 19th Feb 2005 07:31 Edited at: 19th Feb 2005 07:33
have you tried scaling before glueing?

[edit]

the only problem with you method nano is that you can't tell if the viewee is behind a wall or not. The cone method is a quick hack but you could use a simple collision command to determine if the cone collides with any world objects... and if they do, the viewee is not visible.

NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 19th Feb 2005 08:14 Edited at: 19th Feb 2005 08:27
Hexgear,

I would suppose that in using my method, in order to know of any obstructions between the characters, a ray could be shot out from the enemy to the character, in increments, to test for any obstructions. Unfortunately, I have not made it this far in my studies of a.i.

But, I suppose that after doing the tests to see if the player is completely within the enemy's sight limits, then could be placed a quick loop of a ray. If the coords of the ray, traveling from the enemy to the player, at the angle between the charcaters, was to be within an object between the characters at any one point in the loop, then the loop would end and the enemy would not chase the player at that frame. After so, the entire enemy view limit loop would start again.

Here is a simple edit of my code above. I have added a "for next" loop to calculate if there is any obstruction between the characters.


+NanoBrain+
bibz1st
22
Years of Service
User Offline
Joined: 2nd Jan 2003
Location:
Posted: 19th Feb 2005 19:20
steve c,
if you use your cone then you need to OFFSET its position the same amount as you scale it
steve c
21
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 20th Feb 2005 01:55
okay thanks to all u guys i will try my best to use the code u have showed me and stuff but bibz1st what do u mean offset does that mean u can position the cone to a different place after u have glued it

current projects
codename : tasgarad
steve c
21
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 20th Feb 2005 02:21
okay dw about that i have ur code workin nano brain thanks

current projects
codename : tasgarad
blanky
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: ./
Posted: 20th Feb 2005 03:24
W00t! Raytracing!

Avatar - white cat in a snowstorm. Look closely.
steve c
21
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 25th Feb 2005 00:48
...what?

current projects
codename : tasgarad

Login to post a reply

Server time is: 2025-05-23 21:01:25
Your offset time is: 2025-05-23 21:01:25