Hey all
So I've been making something in Yeti3D recently, and I've hit upon a problem. I'm trying to make environmental objects the player can inspect from any side, provided that they're looking towards the object. I've been using a function that Ecko wrote, a long time ago, to fix Bennu/Fenix/DIVs angle wraparound issue, however after a few hours of programming I've discovered angles don't work the same way in Yeti3D - for one, the maximum turn (t, Yeti3Ds version of angle - for looking around using the X axis) that an entity can have isnt as high as the default Bennu angle variable.
What I've been trying is this:
players_angle=playerpos.t; // in player process, after LOOP;
...
// in environmental object process
if (exists(type player));
player_id=get_id(type player);
end
lookatme_angle=get_angle(player_id);
check_player_angle=closest_angle(players_angle, lookatme_angle);
if (yeti_getdistance(placeholdermodelpos, playerpos)<col_radius and check_player_angle<col_span);
// do thing
end
...
// closest angle process
function closest_angle(angle1, int angle2); // Thanks Ecko :)
private
result;
begin
result=(angle2-angle1)%360000;
if (result>180000)
result-=360000;
else
if (result<-180000);
result+=360000;
end
end
if (result<0);
result=abs(result);
end
return (result);
end
I'm just not getting good results - is there something I'm missing, or something someone else could suggest for some good check-if-the-player-is-looking-at-something code??
Thanks guys
Dani
please download "YETI3D R26 11 2012 A.rar"
include lots examples in directory "src\bin\release"
"help.pdf"...
Int YETI_ENTITY_IS_VISIBLE (TYPE_ENTITY_3D entity)
Return true if entity is visible by camera.
int YETI_ENTITY_LINE_OF_SIGHT(TYPE_ENTITY_3D Entity1,TYPE_ENTITY_3D Entity2)
Returns TRUE if two entities have a line of sight.
YETI_ENTITY_LOOK_AT(TYPE_ENTITY_3D Entity, int x, int y, int z )
Setup a entities turn and pitch so it points towards a given point.
if you look to "N" side, exists a resident evil camera .. in mini games example...
to turn objects use vars in entity ... (Yeti3d uses integer math) see "yeti3d.h" file
if (key(_right))
mycam.tt += i2f(3);
end;
if (key(_left))
mycam.tt -= i2f(3);
end;
if (key(_UP))
mycam.xx += YETI_fixsin(mycam.t) >> 4;
mycam.yy += YETI_fixcos(mycam.t) >> 4;
end;
if (key(_down))
mycam.xx -= YETI_fixsin(mycam.t) >> 4;
mycam.yy -= YETI_fixcos(mycam.t) >> 4;
end;
type TYPE_ENTITY_3D
int radius; // 8:8 entity radius.
int x, xx; // 8:8 X position and velocity.
int y, yy; // 8:8 Y position and velocity.
int z, zz; // 8:8 Z position and velocity.
int p, pp; // Pitch and pitch velocity.
int r, rr; // Roll and roll velocity.
int t, tt; // Turn and turn velocity.
int rx; // View space X position.
int ry; // View space Y position
int rz; // View space Z position
end
I already do use vars in entity - if I want to turn the object, I use playerpos.tt+=i2f(2)/playerpos.tt-=i2f(2). This manipulates the turn (t) by using tt as momentum.
Quoteint YETI_ENTITY_LINE_OF_SIGHT(TYPE_ENTITY_3D Entity1,TYPE_ENTITY_3D Entity2)
Returns TRUE if two entities have a line of sight.
So, does this mean if there are no walls between the two entities - OR does it mean if entity1 is looking at and can see entity 2, using entity.t as the looking at angle? Because just there being no obstacles between two entities is not what I mean.
What needs to happen is that one entity needs to be able to see another entity, within 45 degrees of its line of sight - not just for there to be no obstacles between the two entities. Understand? :D
Update: I've tried YETI_ENTITY_LINE_OF_SIGHT(playerpos, objectpos) and it doesnt work. It says there is always line of sight - but I want to check what's in front of playerpos, accounting for their turn / .t - not having any success so far :(
replace tomb raider example for this...
http://www.heypasteit.com/clip/0IIROA (http://www.heypasteit.com/clip/0IIROA)
and function work ok...
Okay, thank you - but I tried that code and it still does not work.
See these images, they may explain my problem better -
(http://i.imgur.com/1JhNdDu.png)
Okay, so I've drawn onto these screenshots the players cone of vision/line of sight. It is an area marked in red in front of the player model, accounting for their turn/angle. In the above screenshot, the object is in front of the players line of sight, and the program says it is, so it is fine. But:
(http://i.imgur.com/UxKZQGa.png)
Here, the object is out of the player charecters vision - they are not facing it, and the program still says that it is in their line of sight.
Does this help explain the problem? I need to be able to tell when one entity is looking at another. (Not turn that entity to face it, but to tell if one entity is already looking at another)
:P ok
i take a look...
Replace tomb raider example ...
https://justpaste.it/1amdj (https://justpaste.it/1amdj)
range of view funtion... ok
Fantastic - just tried this and it worked, thanks l1nk3rn3l. I had a function like this for a previous project I was working on but it only took into account angles, not the turn / .t value that Yeti3D uses - and you're the person who knows the most about Yeti3D, so thanks again :D
Will credit you in game credits - what name should I use?
;D
Okay, seems I spoke too soon - there's a bug in the function. :(
(http://i.imgur.com/chCJD5w.png)
The RangeOfView function says the player is looking at the other model both when it's looking towards it, and looking in the exact other direction. Maybe something to do with how turn / .t wraps around? I'm not sure...
;)
I TAKE A LOOK..
Monsters and NPC's for your game, MD2 Models (Quake2 models)
https://code.google.com/archive/p/otherfenixbennuprojects/downloads?page=2 (https://code.google.com/archive/p/otherfenixbennuprojects/downloads?page=2)
If you publish source code, then will be included in the next Yeti3d game examples pack...
;D
Will credit you in game credits - what name should I use?
Colombian Developers
function RangeOfView(TYPE_ENTITY_3D e1, TYPE_ENTITY_3D e2, int range)
private
TYPE_ENTITY_3D tmp_e;
calculo;
e1_t; //dnt update original
begin
tmp_e= e1;
YETI_ENTITY_LOOK_AT2(tmp_e, e2.x, e2.y, e2.z );//point e1 to e2
if ((e1.t > 0 AND tmp_e.t < 0) OR
(tmp_e.t > 0 AND e1.t < 0) )//Opposite angles
return false;
end
//calcule range of view
e1_t = abs(e1.t); //kill negative signs
tmp_e.t = abs(tmp_e.t);
if (e1_t > tmp_e.t)
calculo = e1_t - tmp_e.t; //caculates range of view
else
calculo = tmp_e.t - e1_t; //caculates range of view
end
if ( calculo <= range AND calculo > 0) //view range
return true;
else
return false;
end
end
Yes! That works, fantastic. Although I had to type it all out by hand, for some reason copy pasting it into the program and compiling gave errors about unrecognized charecters.... :S
Okay - will credit you under that name :) thanks a bunch!!!