ID:151107
 
I like all mobs to have a restricted field of vision. ie they can't see whats happening behind them, how would I accomplish this?

this is for all mobs pc and npc alike
On 4/18/01 7:24 am Kaidorin wrote:
I like all mobs to have a restricted field of vision. ie they can't see whats happening behind them, how would I accomplish this?

this is for all mobs pc and npc alike

Guy did something like this for SpaceTug, but I don't think it's easy...
In response to Deadron
Guy did something like this for SpaceTug, but I don't think it's easy...

Is the above true? If so could you plz help me out.
In response to Kaidorin
Is the above true? If so could you plz help me out.

Yep, it's true, and not that hard to implement, although it's an odd effect--I personally liked it, but a lot of people preferred the traditional view. Whenever the player moved, I simply set client.eye to the turf a few squares ahead of the player. So if you moved north, your mob would appear near the bottom of the screen, and so forth.

I think probably the main reason some people didn't like it is that whenever you changed direction, your mob moved to a different edge of the map. And the movement didn't look as smooth. It never bothered me, though.
In response to Gughunter
Yep, it's true, and not that hard to implement, although it's an odd effect--I personally liked it, but a lot of people preferred the traditional view. Whenever the player moved, I simply set client.eye to the turf a few squares ahead of the player. So if you moved north, your mob would appear near the bottom of the screen, and so forth.

kewl, so I set client.eye. but what about NPC's ?
In response to Kaidorin
kewl, so I set client.eye. but what about NPC's ?

To determine if an NPC can see something, just figure out where it is in relation to the NPC. Something like this:

IsVisible(mob/mySrc, myTarget)
//(Assumes myTarget is in mySrc's view list)
var/targetDir = get_dir(mySrc, myTarget)
if(targetDir in list(turn(mySrc.dir, 180), turn(mySrc.dir, 135), turn(mySrc.dir, -135)) return 0
else return 1
In response to Gughunter
IsVisible(mob/mySrc, myTarget)
//(Assumes myTarget is in mySrc's view list)
var/targetDir = get_dir(mySrc, myTarget)
if(targetDir in list(turn(mySrc.dir, 180), turn(mySrc.dir, 135), turn(mySrc.dir, -135)) return 0
else return 1

hmm I don't get it, I am a bit rusty, could you plz explain a little ;)
In response to Kaidorin
On 4/18/01 11:46 am Kaidorin wrote:
IsVisible(mob/mySrc, myTarget)
//(Assumes myTarget is in mySrc's view list)
var/targetDir = get_dir(mySrc, myTarget)
if(targetDir in list(turn(mySrc.dir, 180), turn(mySrc.dir, 135), turn(mySrc.dir, -135)) return 0
else return 1

hmm I don't get it, I am a bit rusty, could you plz explain a little ;)

I can! =)

IsVisible(mob/mySrc, myTarget)
//(Assumes myTarget is in mySrc's view list)
var/targetDir = get_dir(mySrc, myTarget)
if(targetDir in list(turn(mySrc.dir, 180), turn(mySrc.dir, 135), turn(mySrc.dir, -135)) return 0
else return 1

Get the direction from the source to the target. If the target is directly behind, or behind to the right or left (180 degrees, -135 degrees, 135 degrees), then the NPC can't see that target. If the target isn't behind the NPC, then it can.

So basically you just use

if(IsVisible(NPC, target))
//it can be seen, so do stuff
In response to Spuzzum
IsVisible(mob/mySrc, myTarget)
//(Assumes myTarget is in mySrc's view list)
var/targetDir = get_dir(mySrc, myTarget)
if(targetDir in list(turn(mySrc.dir, 180), turn(mySrc.dir, 135), turn(mySrc.dir, -135)) return 0
else return 1

Get the direction from the source to the target. If the target is directly behind, or behind to the right or left (180 degrees, -135 degrees, 135 degrees), then the NPC can't see that target. If the target isn't behind the NPC, then it can.

So basically you just use

if(IsVisible(NPC, target))
//it can be seen, so do stuff

Think I understand, now where do I put this stuff?
In response to Kaidorin
On 4/19/01 7:11 am Kaidorin wrote:
IsVisible(mob/mySrc, myTarget)
//(Assumes myTarget is in mySrc's view list)
var/targetDir = get_dir(mySrc, myTarget)
if(targetDir in list(turn(mySrc.dir, 180), turn(mySrc.dir, 135), turn(mySrc.dir, -135)) return 0
else return 1

Get the direction from the source to the target. If the target is directly behind, or behind to the right or left (180 degrees, -135 degrees, 135 degrees), then the NPC can't see that target. If the target isn't behind the NPC, then it can.

So basically you just use

if(IsVisible(NPC, target))
//it can be seen, so do stuff

Think I understand, now where do I put this stuff?

IsVisible should be defined as its own top-level proc (i.e. proc/IsVisible()).

Then in the NPC code, if he looks for a user, check IsVisible() when he finds a target.

Eg.

mob/NPC/proc/SearchForPrey()
var/mob/M
for(M in view(src))
if(IsVisible(src, M))
break; //M now contains a target

if(!M) //if haven't found a target
return //then quit

else
//attack M!
In response to Gughunter
Sorry for reviving this ancient topic, however it's not worth it to make a new topic just to ask a simple question. Now, I am planning on using this method of offsetting client.eye by a few tiles when the player moves. However, what happens if they move right up to the edge of the map? "Ahh! Black screen! I can't see!" Not pretty. How did you "fix" this problem, Guy?
In response to Mertek
Dont let client.eye go past certain x and y values? Just a thought.
In response to Mertek
Make the usr's PERSPECTIVE equal the turf that they are on.....