Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 96 Guests
Online:

LATEST FORUM THREADS

»
CoD: Battle Royale
CoD+UO Map + Mod Releases
Damaged .pk3's
CoD Mapping
heli to attack ai
CoD4 SP Mapping

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 4
Category: CoD4 Scripting
Scripting and coding with Call of Duty 4.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername, novemberdobby
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked subscribe
Author Topic: Problem with vectors and angles
hurracane
General Member
Since: Aug 23, 2006
Posts: 58
Last: Oct 24, 2010
[view latest posts]
Level 3
Category: CoD4 Scripting
Posted: Saturday, Aug. 21, 2010 11:44 am
Hai,

I'll get straight to the point, let me get an image to illustrate.



Point A and B are points which I can hopefully get using this:
Code:
a = self.origin + maps\mp\_utility::vectorScale(anglestoforward(self.angles + (0,-45,0), 500);
b = self.origin + maps\mp\_utility::vectorScale(anglestoforward(self.angles + (0,45,0), 500);


I know the coordinates of the player, and I know the coordinates of the little dot (which represents another player) inside the triangle.

1. is the angle between the two lines, hopefully 90 degrees using the method above.

Now, I've tried messing with angles in the form of:
Find out what angle offset the player needs to get in order to look straight at the object in the triangle, If it's less than 45 or -45, and the distance between the two players is less than 500, he'll obviously be in the triangle. (To make things clear, only the horizontal (Y) angle needs to be the same)

This didn't seem to work out how I would've liked it to since I haven't been able to get an actual difference of less than 45 degrees, although the point used was actually within an angle of 45 degrees.

But then again, the method I used might just be completely wrong.

Hm, I just thought of something, what if I compared the distance from player to point A, with the distance of the player to the point in the triangle. If the point is closer to the player than point A, check if it's the same for point B, and if that's the case he must be in the triangle...

Umm, well in any case if anyone is awesome at maths please help me out. [tongue]

edited on Aug. 21, 2010 07:48 am by hurracane
Share |
Tristan4592
General Member
Since: Apr 26, 2007
Posts: 235
Last: Nov 11, 2010
[view latest posts]
Level 4
MODSCON
Im a fan of MODSonair
Category: CoD4 Scripting
Posted: Saturday, Aug. 21, 2010 05:56 pm
If you know the coordinates of the three points, you can use distance formula to calculate the distance between the points, which means you would know the length of all the sides of a triangle formed between the player, either point A or B, and the other player (little dot).

Now because you know all three sides, you can use the law of cosines: http://en.wikipedia.org/wiki/Law_of_cosines to determine any angle in the triangle, in your case, the angle between the line from the player to A or B, and the line from the player to the other player.

This would give you the angle offset between the line from the player to point A or B ( which you know is +- 45 degrees from where the player is looking), to the player in the triangle. Then you can just subtract the offset from the 45, and you should have the number of degrees the player would need to turn to be looking directly at the other player.
Share |
hurracane
General Member
Since: Aug 23, 2006
Posts: 58
Last: Oct 24, 2010
[view latest posts]
Level 3
Category: CoD4 Scripting
Posted: Saturday, Aug. 21, 2010 07:24 pm
Oh the silly cosines.

I hope this is a little bit more reliable than the stuff cod throws at me. I tried getting the angle like this:

Code:
place = self.origin + maps\mp\_utility::vectorScale(anglestoforward(self.angles),150);
place -= (0,25,0);
angle = vectorToAngles(self.origin - place) + (0,180,0);
angle = self.angles[1] - angle[1];


With a point that never changes (var place in the example above) it spewed out random angles.

e.g. 350, 9, 369(what?)

I'll definitely give this a try. I've learned this stuff in school at one point, just forgot all about it.

Thanks! [thumbs_up]
Share |
Xylozi
General Member
Since: Jul 12, 2008
Posts: 218
Last: Mar 1, 2012
[view latest posts]
Level 4
Im a fan of MODSonair
Category: CoD4 Scripting
Posted: Saturday, Aug. 21, 2010 07:48 pm
What exactly are you trying to achieve here? Just wondering since it doesn't seem too clear and can probably be done with an easier method.
Share |
hurracane
General Member
Since: Aug 23, 2006
Posts: 58
Last: Oct 24, 2010
[view latest posts]
Level 3
Category: CoD4 Scripting
Posted: Saturday, Aug. 21, 2010 08:13 pm
attachment: application(335.6Kb)
Well, basically I need to know if any player is within the field of view of another player.

If anyone is, send these bad-ass (not finished at all in the video @ attachment) spikes to kill that person.

I've thought about it, couldn't come up with any other way than doing the actual maths myself.

Note that the video takes place in coduo, though this thread is posted in the cod4 forums. I've done this on purpose because the scripting is the same but mainly because there is an actual scripting forum for cod4.
Share |
Xylozi
General Member
Since: Jul 12, 2008
Posts: 218
Last: Mar 1, 2012
[view latest posts]
Level 4
Im a fan of MODSonair
Category: CoD4 Scripting
Posted: Saturday, Aug. 21, 2010 08:21 pm
Well it would be very easy to check if players are within the vicinity of a player:

Code:

// self is the player checking
CheckOtherPlayers()
{
	players = getEntArray( "player", "classname" );
	for( i = 0; i < players.size; i++ )
	{
		if( distance( self.origin, players[i].origin ) < 100 )	
			players[i] thread DoPunish();
	}
}


That would check if any player is within 100 units of a certain player, and if so enact the punishment on them.
Share |
hurracane
General Member
Since: Aug 23, 2006
Posts: 58
Last: Oct 24, 2010
[view latest posts]
Level 3
Category: CoD4 Scripting
Posted: Saturday, Aug. 21, 2010 08:30 pm
Well yes, that's very easy to do.

I'd like to only obliterate players within the field of view.

I think the maths tristan pointed out will do the job. I sure hope so.

But more importantly, what the hell is this ball so happy for.
[jumping]
Share |
tHMatt
General Member
Since: Sep 11, 2007
Posts: 473
Last: Mar 20, 2013
[view latest posts]
Level 5
Category: CoD4 Scripting
Posted: Saturday, Aug. 21, 2010 09:18 pm
Ok, let me understand.

You want to check if a certain player is in the field of view of another player right, so like, not behind a wall or obstacle?

If so, this is much easier to do then how your approaching it.

I will write a script in a second if this is what your after.

Share |
_INSANE_
General Member
Since: Nov 7, 2008
Posts: 352
Last: Jul 10, 2011
[view latest posts]
Level 5
Im a fan of MODSonair
Category: CoD4 Scripting
Posted: Saturday, Aug. 21, 2010 10:18 pm
This should check for players in view...and make sure you can see them too... in case they are behind something
Code:
blah()
{
	players = getEntArray("player", "classname");
	for(i = 0; i < players.size; i++)
	{
		if(distance(self.origin, players[i].origin) <= 150 && self hasViewOf(players[i]))	
			players[i] thread doWhatever();
	}
}

hasViewOf(target)
{
	//selfHasViewOfTarget
	dot = vectorDot(vectorNormalize(target.origin - self.origin), anglesToForward(self getPlayerAngles()));
	return(dot > cos(45) && target sightConeTrace(self getEye(), self) >= 0.1);
}
Share |
hurracane
General Member
Since: Aug 23, 2006
Posts: 58
Last: Oct 24, 2010
[view latest posts]
Level 3
Category: CoD4 Scripting
Posted: Sunday, Aug. 22, 2010 09:09 am
sightConeTrace doesn't exist, but the way I see it this could just be replaced by a regular bullettrace.

EDIT: It seems to spew out pretty consistent values. I can work with this :D

Thanks insane, but of course thank you tristan and thanks to everyone else too.

edited on Aug. 22, 2010 05:25 am by hurracane
Share |
Restricted Access Topic is Locked subscribe
MODSonline.com Forums : Call of Duty 4 : CoD4 Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»