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 → Homing missile problems
Homing missile problems
2001-05-15, 7:16 AM #1
Here's the code for my homing missile:
Code:
# Jedi Knight Cog Script
#
#This cog is not supported by LEC.

flags=0x240

symbols

template	smoke=+smoke			local
flex		newdist					local
flex		lastdist					local
flex		vecx					local
flex		vecy					local
flex		vecz					local
int		playteam					local
vector	newvel					local
vector	oldvel					local
thing		missile					local
thing		player					local
thing		target					local

message	created
message	pulse

end

# ========================================================================================

code
created:
   lastdist=-1;
   SetthingPulse(GetSenderRef(), 0.05);

Return;

#============================================#

pulse:
   missile = GetSenderRef();
   CreateThing(smoke, missile);
   if((target != -1) && Haslos(missile, target) && (target != player) && (GetThingType(target) == 2 || Getthingtype(target) == 10) && (Getplayerteam(target) != playteam))
   {
	SetThingLook(missile, VectorSub(GetThingPos(target), GetThingPos(missile)));
	Newdist = vectordist(getthingpos(target), getthingpos(missile));
	if((newdist > (lastdist+.1)) && (lastdist != -1))
	{
	   if(vectorx(missile) > 0.3) vecx = -0.1; else vecx = 0;
	   if(vectory(missile) > 0.3) vecy = -0.1; else vecy = 0;
	   if(vectorz(missile) > 0.3) vecz = -0.1; else vecz = 0;
	   newvec = vectorset(vecx, vecy, vecz);
	   oldvec = vectorset(vectorx(missile), vectory(missile), vectorz(missile));
	   Setthingvel(missile, (vectoradd(newvec, oldvec)));
	}
	else ApplyForce(missile, VectorScale(GetThingLVec(missile), 0.2));
   }
   else
   {
	ApplyForce(missile, VectorScale(GetThingLVec(missile), 0.1));
	player = Getlocalplayerthing();
	playteam = GetPlayerTeam(player);
	target = FirstThingInView(missile, 200, 10, 0x404);
   }
   lastdist=newdist;

Return;
#============================================#
end


Now, the missile homes fine, but two missiles can't home in on a target at the same time. Two missile can have a smoketrail and move(use the applyforce) at the same time, but not home. When one missile is homing, any other missile fired will not move. -Though it does have a trail.

What's happening?

------------------
The enemy is in front of us, behind us, to the left, and to the right. This time they won't get away.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-05-16, 7:41 AM #2
GetSourceRef is your problem. It can only have 1 thing number at a time, so I recommend you just make the gun not shoots until the missle blows up.
Hey, I'm here! But who cares?
2001-05-16, 10:28 AM #3
No, GetSenderRef() can be used on more than one thing. Here's LEC's smoketrail cog.

Code:
# Jedi Knight Cog Script
#
# 00_SMOKETRAIL.COG
#
# Leave a smoke trail behind a moving object
#
# [YB]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved

flags=0x240

symbols

template    smoke=+smoke                     local
int         dummy                            local

message     created
message     pulse

end

# ========================================================================================

code
created:
   SetThingPulse(GetSenderRef(), 0.05);            // set 50 msec timer for smoke release

   Return;

# ........................................................................................

pulse:
   dummy = CreateThing(smoke, GetSenderRef());     // create smoke at our current location

   Return;

end   


This will work for more than one rail at a time so I'm sure there's a way to do it. Thanks anyway, Scott. [http://forums.massassi.net/html/wink.gif]

Anyone?

------------------
The enemy is in front of us, behind us, to the left, and to the right. This time they won't get away.

[This message has been edited by SaberMaster (edited May 16, 2001).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-05-16, 11:41 AM #4
Try something like this with looping timers.
Good Luck.

Code:
# Jedi Knight Cog Script
#
#This cog is not supported by LEC.

flags=0x240

symbols

template	smoke=+smoke			local
flex		newdist					local
flex		lastdist					local
flex		vecx					local
flex		vecy					local
flex		vecz					local
int		playteam					local
vector	newvel					local
vector	oldvel					local
thing		missile					local
thing		player					local
thing		target					local

message	created
message	timer

end

# ========================================================================================

code
created:
   lastdist=-1;
   SetTimerEx(0.05, GetSenderRef(), 0, 0);

Return;

#============================================#

timer:
   missile = GetSenderID();
   player = Getlocalplayerthing();
   playteam = GetPlayerTeam(player);
   target = FirstThingInView(missile, 200, 10, 0x404);
   CreateThing(smoke, missile);
   if((target != -1) && Haslos(missile, target) && (target != player) && (GetThingType(target) == 2 || Getthingtype(target) == 10) && (Getplayerteam(target) != playteam))
   {
	SetThingLook(missile, VectorSub(GetThingPos(target), GetThingPos(missile)));
	Newdist = vectordist(getthingpos(target), getthingpos(missile));
	if((newdist > (lastdist+.1)) && (lastdist != -1))
	{
	   if(vectorx(missile) > 0.3) vecx = -0.1; else vecx = 0;
	   if(vectory(missile) > 0.3) vecy = -0.1; else vecy = 0;
	   if(vectorz(missile) > 0.3) vecz = -0.1; else vecz = 0;
	   newvec = vectorset(vecx, vecy, vecz);
	   oldvec = vectorset(vectorx(missile), vectory(missile), vectorz(missile));
	   Setthingvel(missile, (vectoradd(newvec, oldvec)));
	}
	else ApplyForce(missile, VectorScale(GetThingLVec(missile), 0.2));
   }
   else
   {
	ApplyForce(missile, VectorScale(GetThingLVec(missile), 0.1));
   }
   lastdist=newdist;
   if(GetLifeLeft(missile) >= 1)
   {
   SetTimerEx(0.05, missile, 0, 0);
   }
Return;
#============================================#
end


- Wisdom is 99% experience, 1% knowledge. -
2001-05-16, 6:21 PM #5
I get the same error: When a missile has a
target, any other missile created after it
will not move until the first missile loses
its target. So, is there a way I could have individual things and distances in this cog?

------------------
The enemy is in front of us, behind us, to
the left, and to the right. This time they won't get away.

[This message has been edited by SaberMaster (edited May 16, 2001).]

[This message has been edited by SaberMaster (edited May 16, 2001).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-05-19, 3:37 PM #6
Anyone? [http://forums.massassi.net/html/confused.gif]

BTW, I have some errors in the cog above with the vectorx, y, and z, and I've fixed them now. They weren't any real problem.

------------------
The enemy is in front of us, behind us, to the left, and to the right. This time they won't get away.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

↑ Up to the top!