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 → Piercing Projectile Problems
Piercing Projectile Problems
2003-12-04, 1:14 PM #1
I was experimenting with the proj_pierce.cog from Millennium, and I've run into a problem with it. The projectile gets reinserted and everything, but it is offset a bit. Instead of creating the proj directly behind the victim, it is offset to the right or left, but rarely appears where it's supposed to. Here's a pic.
[http://blargh.mine.nu/test/169/5.jpg]
The first one shows me shooting the bullet (modified with the bry1.3do model and to go 3 jku/s) toward a mag-sealed glass pane in JK level 1. The bullet should bounce back and hit me in the head, as it did in the second pic (where the blood pars are flying from), but the new projectile reppears to my right. Here's the code I'm using
Code:
# Jedi Knight Missions Cog Script
#
# PROJ_RAIL.COG
#

symbols

message	touched

end

#----------------------------------------------------------------------------

code

touched:

	victim = GetSourceRef();
	bullet = GetSenderRef();

	dir = GetThingLVec(bullet);

	vec = VectorScale(VectorSub(GetThingPos(victim), GetThingPos(bullet)), -1);
	bullet = FireProjectile(victim, GetThingTemplate(bullet), -1, -1, vec, '0 0 0', 0, 0, 0, 0);

	SetThingVel(bullet, VectorScale(vectornorm(dir), 3));
	SetThingLook(bullet, dir);

	return;

end

Can anyone help me out? I'm not that great with vectors yet, and I'm stumped on how to fix this. (if necessary, I won't use this feature)

------------------
[Meow Mix]
Meow Meow Meow Meow
Meow Meow Meow Meow
Meow Meow Meow Meow Meow Meow Meow Meow
May the mass times acceleration be with you.
2003-12-05, 2:44 AM #2
I can tell you right off the bat that the vector is a little off because of the math and use of FireProjectile(). (Not only that, but the parent of the projectile is now the person who got hit with it)


This should work with no problems

Code:
# Piercing projectile
#
# Created By: Hell Raiser [Jon Harmon]
# Concept from Heidiki

symbols

message		touched

end

code

touched:

	Proj=GetSenderRef();
	Victim=GetSourceRef();

	Dir=GetThingLVec(Proj);

	//This will get a direction vector 0.1 infront of Proj's look vector, and add that
	//to the position of the victim.  Result is Proj being 0.1 JKU's away from the victim

	NewPos=VectorAdd(VectorScale(Dir, 0.1), GetThingPos(Victim));

	NewProj=CreateThingAtPos(GetThingTemplate(Proj), GetThingSector(Victim), NewPos, '0 0 0');

	SetThingLook(NewProj, Dir);

return;

end



------------------
-Blessed Be-
I know it's the last day on earth,
We'll be together while the planet dies.

DBZ: The Destruction is Real
-Hell Raiser
2003-12-05, 4:25 AM #3
i think this will not work fine. Its couse you dont kill old shot, so there will be exlodion and then new shot. Why you dont look how lec done this (try old crosborrow).. ?

------------------
The miners of Kiith Somtaaw sacificed much, and risked all. For their efforts they were brought into the inner most circle of Hiigaren power. Naabal, S'jet, and Sobanii bowed before them. And from that day to this, Somtaaw's children have been known to one and all as Beastslayers..
2003-12-05, 11:10 AM #4
(I left this post intact due to it's importance in the fixing of the problem)
Hell Raiser. Your cog doesn't really work. At least not for me. I fire the bullet, and when it goes thru the target, it will often launch away on some seemingly random vector. Sometimes, it even attaches itself to the target and continues to hit them until they cannot be touched again.

------------------
[Meow Mix]
Meow Meow Meow Meow
Meow Meow Meow Meow
Meow Meow Meow Meow Meow Meow Meow Meow

[This message has been edited by Darth Slaw (edited December 05, 2003).]
May the mass times acceleration be with you.
2003-12-05, 11:56 AM #5
Hellraiser, your cog would have worked correctly if it had this line:
{b]SetThingVel(newproj, VectorScale(VectorNorm(dir), velocity));[/b]
I fixed it and it works PERFECTLY! Thank you Hell Raiser. Here is the fixed cog.

Code:
# Piercing projectile Cog
#
# class_pierce.cog
#
# Created By: Hell Raiser [Jon Harmon]
# Concept from Heidiki
# Projectile creation bug fixed by Darth Slaw
# 
#==============================================================#
symbols

message   touched

int       proj          local
int       newproj       local
int       victim        local
flex      velocity=100  local

vector    dir           local
vector    newpos        local

end
#==============================================================#
code
#------------------------------------------------------
touched:
	proj = GetSenderRef();
	victim = GetSourceRef();
	dir = GetThingLVec(proj);

	//This will get a direction vector 0.1 infront of Proj's look vector, and add that
	//to the position of the victim.  Result is Proj being 0.1 JKU's away from the victim
	newpos = VectorAdd(VectorScale(dir, 0.1), GetThingPos(victim));
	newproj = CreateThingAtPos(GetThingTemplate(proj), GetThingSector(victim), newpos, '0 0 0');
	SetThingLook(newproj, dir);
	
	//the cog needs this next line, or it won't fire the projectile
	// along the right vector. Change the velocity of the new projectiles
	// with the velocity symbol in the symbols section
	SetThingVel(newproj, VectorScale(VectorNorm(dir), velocity));

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

In Heideki's original code, it had the SetThingVel(blah blah blah) line. When I removed it, not knowing it fired the projectile correctly, it fired with the same bug as Hell Raiser's -- random vectors. After thinking about it, I wondered what would happen if I put that line in HR's code. To my surprise, it fixed the prob.
Thanks for helping me out! [http://forums.massassi.net/html/biggrin.gif]


------------------
[Meow Mix]
Meow Meow Meow Meow
Meow Meow Meow Meow
Meow Meow Meow Meow Meow Meow Meow Meow
May the mass times acceleration be with you.
2003-12-06, 12:24 AM #6
Doh! Thats right! When I created it, I didn't set it's velocity, so it would fire out based on a vector where you were standing, ect ect. Gotta set the look and/then velocity. Oh well, least I made a spark. [http://forums.massassi.net/html/smile.gif]

------------------
-Blessed Be-
A solid challenge will bring forth your finest abilities.
DBZ: The Destruction is Real
-Hell Raiser

↑ Up to the top!