1 registered members (7th_zorro),
793
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Vorne oder hinten?
#148368
08/16/07 18:02
08/16/07 18:02
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
OP
Serious User
|
OP
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Hi! Ich habe mal wieder ein Problem Ich möchte wissen, ob ich vor oder hinter einer entity bin, nachdem ich diese brührt habe... Hatte mal nen Ansatzt mit winkelfunktionen, doch der erwies sich leider als falsch! Vielleicht habt ihr ja eine idee wie man soetwas brechnen könnte? Danke für eure hilfe! Mfg Dark_samurai
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: Vorne oder hinten?
[Re: Dark_samurai]
#148369
08/16/07 18:29
08/16/07 18:29
|
Joined: Jul 2007
Posts: 959 nl
flits
User
|
User
Joined: Jul 2007
Posts: 959
nl
|
hello
var varargwhy; var varwhy;
while(my != null && you != null) { varargwhy = my.pan; varwhy = you.pan; varargwhy += 90; //change 90 if(varargwhy >= varwhy) { my.pan +=180; } varargwhy -= 90; //change 90 if(varargwhy <= varwhy) { my.pan +=180; } wait(1); } }
Last edited by flits; 08/16/07 19:34.
"empty"
|
|
|
Re: Vorne oder hinten?
[Re: flits]
#148370
08/16/07 18:58
08/16/07 18:58
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
OP
Serious User
|
OP
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Hi! @filts: Thanks for your quick answer! Quote:
my.pan = varargwhy; you.pan = varwhy;
This must be wrong? did you meant: varargwhy = my.pan;...?
I'm soory for my realy bad explaination so I explain it again (this time in english): I want a Code, which shows me if my Player stands behind or in front of the Object he touched. But it should do it like that: every thing behind the green line should be calculated as behind and everything in front of the line in front! So the pan of the Objekt should also be used! I hope everybody understood my explaination and sorry for my bad english!
Dark_samurai
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: Vorne oder hinten?
[Re: flits]
#148372
08/16/07 20:01
08/16/07 20:01
|
Joined: Jul 2007
Posts: 959 nl
flits
User
|
User
Joined: Jul 2007
Posts: 959
nl
|
i am trying out somthing but maby u can do somthing white this
vec_to_angle (ANGLE* ang, VECTOR* dir); Computes the pan and tilt angles of a direction vector, and places them into the pan and tilt parameters of an Euler angle. Very useful for trading an angle for a direction, thus computing the angles to a target. Parameters: ang Euler angle to be calculated. dir direction vector.
Modifies: ang
Speed: Fast Example: function turn_towards_target() { // get the direction from the entity MY to the entity YOU vec_set(temp,your.x); vec_sub(temp,my.x); vec_to_angle(my.pan,temp); // now MY looks at YOU } See also:
Last edited by flits; 08/16/07 20:04.
"empty"
|
|
|
Re: Vorne oder hinten?
[Re: flits]
#148373
08/16/07 20:12
08/16/07 20:12
|
Joined: Jul 2007
Posts: 959 nl
flits
User
|
User
Joined: Jul 2007
Posts: 959
nl
|
retry
var varargwhy; var varwhy; string* string_argwhy = " ";
while(my != null && you != null) { varargwhy = my.pan; vec_set(temp,your.x); vec_sub(temp,my.x); vec_to_angle(argwhy,temp); varargwhy += 90; //change 90 if(varargwhy >= varwhy) { str_cpy(string_argwhy,"i am behind"); } varargwhy -= 90; //change 90 if(varargwhy <= varwhy) { str_cpy(string_argwhy,"i am behind)"; } wait(1); } }
"empty"
|
|
|
Re: Vorne oder hinten?
[Re: flits]
#148374
08/17/07 20:04
08/17/07 20:04
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
OP
Serious User
|
OP
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
@filts: Sorry but your Code doesn't work...
After a few hours I got my old idea run without any mistakes. If there is anybody interested into the code than please send me a PM!
Dark_samurai
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: Vorne oder hinten?
[Re: Dark_samurai]
#148375
08/19/07 08:22
08/19/07 08:22
|
Joined: Oct 2003
Posts: 312 Lüneburg, Germany
Gnometech
Senior Member
|
Senior Member
Joined: Oct 2003
Posts: 312
Lüneburg, Germany
|
With the dot product this is really simple... The dot product of two vectors is positive, if they "point in the same direction" (i.e. the angle between them is less than 90 degrees), it is zero if they are perpendicular to each other and negative if the angle between them is greater than 90 degrees. So, you want to know if Ent1 is in front of Ent2 or behind. Just calculate the "view" vector of Ent2, that is a vector (say of length 1) pointing in front of Ent2. This can be done by two lines: Code:
vec_Set(temp, vector(1,0,0)); vec_rotate(temp, ent2.pan);
Then define a vector pointing from ent2 to ent1. One line of code: Code:
vec_diff(temp2, ent1.x, ent2.x);
Of course temp2 has to be defined first. ;-) Last, just check the dot product: Code:
if (vec_dot(temp,temp2) > 0) { // Ent1 is in front of Ent2 ... } else { // Ent1 is behind Ent2 ... }
And that's it. Three lines and then a test. Regards, Gnometech
Last edited by Gnometech; 08/19/07 15:12.
|
|
|
Re: Vorne oder hinten?
[Re: Gnometech]
#148376
08/19/07 14:04
08/19/07 14:04
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
OP
Serious User
|
OP
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Wow! I needed other 6 hours to get my code run which is 14 lines long and than you come with i code which is nearly 1/4 of mine and seems to be very smiple I made it like that: Code:
Playerpos_rel.x = my.x - LeiterP.x; //Calculates the relative Playerposition in x direction Playerpos_rel.y = my.y - LeiterP.y; //Calculates the relative Playerposition in y direction if(sin(Leiter_pan) != 0 && sin(Leiter_pan) != 1 && sin(Leiter_pan) != -1) //Leiter_pan != ...,-180,-90,0,90,180,... { if((Playerpos_rel.y/tan(Leiter_pan)) > LeiterP.x) {Vorderbei = 1;} //Playerentity is in front } if(sin(Leiter_pan) == 0) //Leiter_pan == 0,180,... { if(my.y < LeiterP.y) {Vorderbei = 1;} //Playerentity is in front } if(sin(Leiter_pan) == 1 || sin(Leiter_pan) == -1) //Leiter_pan == ...,-90,90,... { if(my.x > LeiterP.x) {Vorderbei = 1;} //Playerentity is in front }
Dark_samurai
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
|