Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Vectors, positions, oy vey!.........
Vectors, positions, oy vey!.........
2002-01-04, 10:33 PM #1
Here's what I'm trying to do. I want to fire a ghost then a projectile and have the ghost always be in the middle of the screen, moving forward, while having a 0.1 jku lead on the projectile behind it. Basically the ghost will be a guide for the projectile so that the projectile moves towards the crosshair.

Think of a mile long bar extending from inbetween kyles eyes. [http://forums.massassi.net/html/smile.gif] I want the ghost to always stay on that bar, moving forward on it, no matter where kyle is looking, while maintaining a 0.1 jku lead on the projectile.

I think I can do it with something similar to this:

Pulse:

Lvec=GetThingLVec(headpitchghost);
FancyVector=Something based off LVec combined with some GetThingPos's + 0.1; ???
SetThingPos(centerproj, FancyVector);
SetThingLVec(centerproj, LVec);
SetThingVel(projectile, VectorSub(GetThingPos(centerproj), GetThingPos(projectile), #));

return;

I just need to know what FancyVector needs to be in order to get it all worked out.

I hope I haven't confused anyone, because this is the best that I can explain it. [http://forums.massassi.net/html/smile.gif]

------------------
-Hell Raiser
Cogging type person that does, umm, stuff?
"Free, your, mind."
DBZ: TDIR has a new home!

[This message has been edited by Hell Raiser (edited January 05, 2002).]
-Hell Raiser
2002-01-05, 8:39 AM #2
It's SetThingLook() not SetThingLVec() and VectorSub() has two params. [http://forums.massassi.net/html/tongue.gif]

The code:
Code:
#----------------------------------------------------------------
activated:
	player=jkGetLocalPlayer();
	gthing=CreateThing(gtemp, player);
	SetPulse(0.01);

Return;
#----------------------------------------------------------------
pulse:
	pos1=VectorAdd(GetThingPos(player), VectorSet(0, 0, 0.03));
	pos2=VectorScale(VectorNorm(GetThingLVec(player)), 0.15);
	gpos=VectorAdd(pos2, pos1);
	SetThingPos(gthing, gpos);

Return;
#----------------------------------------------------------------


That code will keep a ghost in front of the player at eye level. pos1 gets a pos a 0.05 JKUs above the player. pos2 gets a vector 0.15 JKUs in front of him. Add them together and voila!

And of course, SetThingPos() won't let you see the ghost once you get out of the sector it was created in.

[This message has been edited by SaberMaster (edited January 05, 2002).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-01-05, 9:29 AM #3
Actually, pos1 gets a pos 0.03 JKUs above the player.

Does anybody else have a problem with editing a post more than once?
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-01-05, 10:32 AM #4
I was up late, and you know what staying up late can do to ya. [http://forums.massassi.net/html/tongue.gif] That's why I fudged up some stuff. (I certianly wouldn't have done it in the cog [http://forums.massassi.net/html/biggrin.gif])

Anyway, /me hugs SaberMaster untill vital organs ooze out of his ears [http://forums.massassi.net/html/biggrin.gif]

I used your code as a base as I had to get the "proper" LookVector of the player. Here's what I've got:

Code:
# Test stuff

symbols

thing		player			local
thing		CrossHair		local
thing		HeadPitch=-1		local
template	AP_tpl=+APGhost	local

model		Def=dflt.3do	local

vector		pos1			local
vector		pos2			local
vector		CHPos			local

flex		Distance=0		local

message		user0
message		user1
message		pulse
message		startup

end

code

startup:

	Sleep(2);
	Call user1;

return;

pulse:

	HeadPitch=FireProjectile(player, AP_tpl, -1, -1, '0 0 0', '0 0 0', 1.0, 0x20, 0, 0);
	pos1=VectorAdd(GetThingPos(HeadPitch), VectorSet(0, 0, 0.057));
	Distance=Distance+0.001;
	pos2=VectorScale(VectorNorm(GetThingLVec(HeadPitch)), Distance);
	//pos2=VectorScale(VectorNorm(GetThingLVec(HeadPitch)), 0.15);
	CHPos=VectorAdd(pos2, pos1);
	SetThingLook(CrossHair, GetThingLVec(HeadPitch));
	SetThingPos(CrossHair, CHPos);
	if(HeadPitch!=-1) DestroyThing(HeadPitch);
	
return;

user1:
	Player=GetLocalPlayerThing();
	CrossHair=FireProjectile(player, AP_tpl, -1, -1, '0 0 0', '0 0 0', 1.0, 0x20, 0, 0);
	SetThingModel(CrossHair, def);

	SetPulse(0.01);
return;

user0:
	SetPulse(0);
return;

end


Ok, so in pos2=VectorScale(VectorNorm(GetThingLVec(HeadPitch)), 0.15); it gets 0.15 infront of headpitch, where ever headpitch is looking. So in order to make CrossHair move forward while staying in the center of the screen, I would replace 0.15 with say Distance, and modify Distance to suit my needs! w00t! [http://forums.massassi.net/html/biggrin.gif]

Hey, could you explain what each line does so that I can have a better understanding of what is being done with the Vector stuff? [http://forums.massassi.net/html/smile.gif]

Thanks a bunch SaberMaster!

[edit]I added in moving forward, but when I look up or down, it strays a bit below the center of JKs crosshair. =\[/edit]

[edit]Replaced previous posted cog with new one with moving forward[/edit]

Oh, I don't seem to have a problem with editing posts more than once.....

[edit]Twice....[/edit]
[edit]Thrice....[/edit]
[edit]Hmmmmm, I have no idea what your problem could be with editing posts, works fine for me......[/edit]

------------------
-Hell Raiser
Cogging type person that does, umm, stuff?
"Free, your, mind."
DBZ: TDIR has a new home!

[This message has been edited by Hell Raiser (edited January 05, 2002).]
-Hell Raiser
2002-01-05, 5:13 PM #5
So small stuff but hey, wasn't the eye-height 0.037? [http://forums.massassi.net/html/smile.gif]

------------------
http://millennium.massassi.net/ - Millennium
2002-01-05, 5:58 PM #6
Hideki, in my static.jkl, eyeoffset=(0/0/0.057) for walkplayer.

------------------
-Hell Raiser
Cogging type person that does, umm, stuff?
"Free, your, mind."
DBZ: TDIR has a new home!
-Hell Raiser
2002-01-05, 6:45 PM #7
You changed it from the default value.
Check the master.tpl. It's at 0.037.

------------------
http://millennium.massassi.net/ - Millennium
2002-01-05, 7:08 PM #8
Hideki in my master.tpl it says what your saying there. But if you fire a projectile at the co-ordinate as 0.57 then it goes perfectly down the centre of the screen.
Team Battle.
2002-01-07, 6:45 AM #9
You're welcome, HR. Glad to help [http://forums.massassi.net/html/wink.gif]

Anyways, I don't think you have to even use vector calculations for what you want to do. Try this:

Code:
#----------------------------------------------------------------
activated:
	player=jkGetLocalPlayer();
	gthing=CreateThing(gtemp, player);
	SetPulse(0.01);

Return;
#----------------------------------------------------------------
pulse:
	tempghost=FireProjectile(player, gtemp, -1, -1, '0 0.15 0.035', '0 0 0', 1, 0, 0, 0);
	gpos=GetThingPos(tempghost);
	SetThingPos(gthing, gpos);
	DestroyThing(tempghost);

Return;
#----------------------------------------------------------------
deactivated:
	SetPulse(0);
	DestroyThing(gthing);

Return;
#----------------------------------------------------------------


The code would be simpler if there wasn't an intermediate ghost to find the position, but I think you'd want to have only one ghost to aim the projes at.

The problem with the old code was adding the 0.03 (or whatever) to the player's position. I should have realized that wouldn't work when the player pitched. [http://forums.massassi.net/html/redface.gif]

Oh, and I found out what that edit problem was. Opera wasn't reloading the edit box every time I tried to edit my post.

------------------
More matter with less art.

[This message has been edited by SaberMaster (edited January 07, 2002).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-01-07, 7:35 AM #10
Quote:
<font face="Verdana, Arial" size="2">Hey, could you explain what each line does so that I can have a better understanding of what is being done with the Vector stuff?</font>


Sure. I have only a vague understanding of vectors myself, but I'll explain as best I can. [http://forums.massassi.net/html/wink.gif]

First, many editors (And the JKSpecs in particular) don't make any distinction between a vector and a position(AKA point); this is partly because LEC defines a position as a vector symbol type and vector verbs use positions. A vector is: A magnitude and a direction which can be expressed as three numbers.

---

The first line was:

pos1=VectorAdd(GetThingPos(player), VectorSet(0, 0, 0.03));

This basically gets a position 0.03 JKU's above the player's position.

---

pos2=VectorScale(VectorNorm(GetThingLVec(player)), 0.15);

This line gets an offset for the player's pos. The lvec of the player is normalized; that is, it is reduced proportionally to give the vector a length of 1. The direction of the lvec is not lost, but the original magnitude is. Basically, normalizing the lvec prepares it for scaling. [edit] I'm pretty sure the lvec returned by GetThingLVec() is already normalized, but just to be safe...

Scaling a vector is simply multiplying the vector's three numbers by the number you scale with. We are scaling the vector by 0.15 in that line of code. The direction is not changed, only the magnitude. The reason to scale the vector is to set the magnitude (length) to the number we want.

So, the pos2 (it's not really a position) vector has the direction of the lvec and a length of 0.15.

---

gpos=VectorAdd(pos2, pos1);

This line adds the position and vector together. Vector addition is simple; for example '1 0 0' + '0 0 1' == '1 0 1'. The pos2 vector is used to offset the pos1 position by 0.15 JKUs in the direction of the lvec.

----

Yeah, my description is hard to understand (and may not be entirely correct), but that's the best I can describe what I'm doing with those vector verbs. For a better resource, read Alexei Novikov's vector tutorials.

------------------
More matter with less art.

[This message has been edited by SaberMaster (edited January 08, 2002).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-01-08, 7:20 PM #11
You explained it wonderfully! [http://forums.massassi.net/html/biggrin.gif] I kinda had a loose grasp on it, but you have reinforced that loose grasp. [http://forums.massassi.net/html/smile.gif] Thanks!

[edit]Hey, it's a small world! [http://forums.massassi.net/html/smile.gif] Took a peek at yer profile, and I live in NC too! [http://forums.massassi.net/html/biggrin.gif][/edit]

------------------
-Hell Raiser
Cogging type person that does, umm, stuff?
"Free, your, mind."
DBZ: TDIR has a new home!

[This message has been edited by Hell Raiser (edited January 08, 2002).]
-Hell Raiser
2002-01-09, 11:25 AM #12
Yeah, the internet does make the world a lot smaller. [http://forums.massassi.net/html/smile.gif]

Glad you got the gist of those vectors. [http://forums.massassi.net/html/wink.gif]

------------------
More matter with less art.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

↑ Up to the top!