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 → Need help getting started
Need help getting started
2004-06-20, 9:21 AM #1
Alright, so I'm going to at least START on a little project. Basically what I want to do is set up a very flexible 3rd person camera. The main feature I'm going for is the ability to have the player's aim position itself based on where the camera is aiming (not based on the DIRECTION the camera is aiming)

I'm not sure where to start looking around for how to do that. I'm just doing this for fun, and maybe some learning, not a real project or anything. IF any of you know mods or the like that did similar things or maybe an idea about a better way to implement something like this (a "dummy" player with the normal player acting as the camera?) I'd appreciate the help.

------------------
WOOSH|-----@%
Warhead[97]
2004-06-20, 9:40 AM #2
Maybe something like this?

Code:
# Jedi Knight Cog Script
#
# External_Camera.COG
#
# External camera that looks where you are aiming.
# 
# [Darth Slaw]
# 
# This Cog is Not supported by LucasArts Entertainment Co

flags=0x240

symbols

message		startup
message		newplayer
message		pulse
message		timer
message		killed

thing		cam			local
thing		dummy			local
thing		player			local

template	cam_tpl=+Zoom_Cam	local

end

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

code
startup:
newplayer:
	player = GetLocalPlayerThing();
	SetCameraFocus(1, player);
	SetTimerEx(1.0, 10, 0, 0);

stop;
# ........................................................................................
pulse:
	print("hahahaha");
	cam = FireProjectile(player, cam_tpl, -1, -1, '0 -0.2 0.12', '0 0 0', 0, 0, 0, 0);
	//SetThingPos(cam, VectorAdd(GetThingPos(cam),VectorScale(GetThingLVec(cam), 0.05))); //to prevent HOM
	dummy = FireProjectile(player, cam_tpl, -1, -1, '0 10 0', '0 0 0', 0, 0, 0, 0);    //where we are aiming
	SetThingLook(cam, VectorSub(GetThingPos(dummy), GetThingPos(cam)));
	SetCameraFocus(1, cam);

stop;
timer:
	if(GetSenderID() == 10) SetPulse(0.01);

stop;
killed:
	if(GetSenderRef() == player) SetPulse(0);

stop;
end

And your camera templates
Code:
_cambase	none		orient=(0/0/0) type=weapon collide=1 move=physics thingflags=0x20000000 mass=5 physflags=0x200 maxrotvel=90 damageclass=0x2 typeflags=0x1
+Zoom_Cam	_cambase	size=0.02 movesize=0.02 maxvel=0 vel=(0/0/0) timer=0.01 thingflags=0 damageclass=0 typeflags=0x5

Tested -- camera is a little jumpy when you change your aim from something close to something far away, and, due to JK's horrible thing collision system, will sometimes look at a point somewhere along the line which you are aimimg (before the actual hit point of the "pointer" that is fired) when you aim at a thing. Also, if you tilt your head down far enough, the cam will look backwards. This could be fixed with a ParseArg(player, "minheadpitch=[angle]") command upon the cam's activation, and reset to the full value upon deactivation.

Hope this helps. [http://forums.massassi.net/html/smile.gif]

btw, I finally remembered all the params for the FireProjectile() verb [http://forums.massassi.net/html/biggrin.gif] yay for me!

------------------
nytfyre m0d || f33l t3h p0w3r || t3h l0st c0gz || OMF > *

[This message has been edited by Darth Slaw (edited June 20, 2004).]
May the mass times acceleration be with you.
2004-06-20, 11:06 AM #3
Are you referring to a freelancer-esque weapons mode, where it aims at the closest object along a certain line? If so, then I could really use the answer to help my mod a LOT. If not, I'll just start my own thread [http://forums.massassi.net/html/smile.gif] and try to figue what you mean.

------------------
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
2004-06-20, 12:32 PM #4
Well this might help, its a cog i threw together that creates
a stationary ghost camera, all you have to do is figure out how to rotate it the way you want....

Code:
# Jedi Knight Cog Script
# FORCE_THROW.COG - GHOST CAMERA
# by EAH_XxLuNaTiKxX

symbols

thing       player                           local
thing       potential                        local
thing       debris                           local
thing       victim                           local

flex        mana                             local
flex        maxDot                           local
flex        dot                              local
flex        cost=0                          local
int         rank                             local

vector      dir                              local

sound       throwSound=orceJump02.wav      local

int         active=0                         local
template    GHOST=ghost                local

message     startup
message     activated
message     deactivated
message     pulse
message     newplayer
message     killed
message     deselected
message     selected

end

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

code

startup:
   player = GetLocalPlayerThing();

   Return;

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

   // Cannot use power if blinded
   if(GetActorFlags(player) & 0x800) Return;

   if(active) Return;

   mana = GetInv(player, 14);
   rank = GetInv(player, 30);

   if(mana >= cost)
   {
      victim = -1;
      active = 1;
      SetInvActivated(player, 30, 1);
      SetPulse(0.33);
   }
   Return;

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

   // Check all things for our victim.
   victim = -1;
   maxDot = 0;

   // Search for all players and actors.
   potential = FirstThingInView(player, 50 + 10 * rank, 7, 0x404);
   while(potential != -1)
   {
      if(
         HasLOS(player, potential) &&
         (potential != player) &&
         (VectorDist(GetThingPos(player), GetThingPos(potential)) <= 4) &&
         !(GetThingFlags(potential) & 0x200) &&
         !(GetActorFlags(potential) & 0x100) &&
         !((jkGetFlags(potential) & 0x20) && !IsInvActivated(player, 23))
        )
      {
      }
         dot = ThingViewDot(player, potential);
         if(dot > maxDot)
         {
            victim = potential;
            maxDot = dot;
         }
      potential = NextThingInView();
   }

   // If we have a victim...
   if(victim != -1)
   {
      jkSetTargetColors(5, 15, 20);
      jkSetTarget(victim);
   }
   else
   {
      jkEndTarget();
   }

   Return;

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

   
   // Cannot use power if blinded
      victim = FirstThingInView(9 + 10 * 10, 1 + 99);   // 0x010 debris
   LUNATIK = LUNATIK + 1;
   call stop_power;
   call stop_power;
   
activated:
   if(GetActorFlags(player) & 0x20)
   {
   Print("CAMERA DE-ACTIVATED AND RETURNED TO USER");
   SetCameraFocus(0, player);
   TEST = ClearActorFlags(player, 0x20);	 	  	
   SetInvActivated(player, 30, 0);
   Return;
   }
   if((GetInv(player, 30) == 0) || (GezThingHealtz(player) >= 0))
   {
   Print("STATIONARY CAMERA PLACED AND ACTIVATED");
   DUMMY = CreateThing(GHOST, player);
   SetCameraFocus(0, DUMMY);
   SetActorFlags(player, 0x20);		
   SetInvActivated(player, 30, 1);
   }
deactivated:
pulse:
   	
      Return;

   
   if(mana >= cost)
   {
      if(HasLOS(player, victim))             // check that we still have a LOS on it...
      {
      }
         
         PlaySoundThing(throwSound, player, 1.0, -1, -1, 0x80);
         if(GetInv() != 1) ChangeInv(14, NextThingInView());
         
         // Check for debris objects in view.
                  while(debris != -1)
         {
         }
            if(HasLOS(player, debris))
            {
            }
               dir = VectorScale(VectorNorm(VectorSub(victim, 0)), -0.0);
   }

   
   Return;

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

selected:
   SetPhysicsFlags(victim, 0x400000);
   Return;

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

   jkEndTarget();
deselected:
   Return;

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

killed:
   if(GetSenderRef() != player) Return;

newplayer:
   call stop_power;

   Return;

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

stop_power:
   SetPulse(0);
   SetInvActivated(player, 30, 0);
   active = 0;
   jkEndTarget();

   Return;

end

# By EAH_XxLuNaTiKxX
# Coded to Pass Checksum #


[Code tags, please...]


test it, works in mp and sp....

------------------
eternity is the now ~ that never was

[This message has been edited by EAH_XxLuNaTiKxX (edited June 20, 2004).]

[This message has been edited by GBK (edited June 26, 2004).]
2004-06-20, 1:08 PM #5
Wow, you guys are like...cog geniuseses. [http://forums.massassi.net/html/smile.gif]

You just whipped that out and it works perfectly!

However...it's not exactly what I was looking for. It's in reverse. That's why I'm really not sure how to do it...i want the player to turn to look at where the camera is pointing, rather than the camera look where the player is pointing. Is that possible?

------------------
WOOSH|-----@%
Warhead[97]
2004-06-20, 2:46 PM #6
You need the (code)(/code) tags. Replace the ()'s with []'s.

Code:
JediKirby


------------------
-Proud Leader of the Minnessassian Council
<]-[ellequin> Nothing is quite as satisfying as placing a .177 lead pellet in between the eyes of a cat.
<]-[ellequin> I think I will leave it's corpse there, to warn all the other cats to keep out of my hibiscus patch

Live on, Adam.
ᵗʰᵉᵇˢᵍ๒ᵍᵐᵃᶥᶫ∙ᶜᵒᵐ
ᴸᶥᵛᵉ ᴼᵑ ᴬᵈᵃᵐ
2004-06-20, 4:49 PM #7
Quote:
<font face="Verdana, Arial" size="2">Originally posted by BobTheMasher:
However...it's not exactly what I was looking for. It's in reverse. That's why I'm really not sure how to do it...i want the player to turn to look at where the camera is pointing, rather than the camera look where the player is pointing. Is that possible?</font>


It is except you can't change the headpitch to match (I don't think; maybe I'm wrong).

------------------
nytfyre m0d || f33l t3h p0w3r || t3h l0st c0gz || OMF > *
May the mass times acceleration be with you.
2004-06-25, 9:35 PM #8
Just a quick bit of help again:

I've got this:

Code:
camlook = VectorAdd(camlook, VectorSub(GetThingPos(dummy), GetThingPos(cam))*.1);
SetThingLook(cam, camlook);


And it isn't setting the look...I'm obviously doing something wrong...could you tell me what?

------------------
WOOSH|-----@%

[This message has been edited by BobTheMasher (edited June 26, 2004).]
Warhead[97]
2004-06-25, 10:49 PM #9
"GetThingPos(cam))*.1"

At a quick glance it looks like you're trying to multiply a vector by a real number. That isn't possible by just using a multiply symbol (*), gotta use a verb to make that sorta change to a vector.

VectorScale(GetThingPos(cam), 0.1) would probably do it.

Quib Mask

P.S. - Lunatik, "sound throwSound=orceJump02.wav local" is bad form that many cog "hackers" picked up for some reason. If you don't keep the sounds the same throughout your cogs, you can cause sounds to not match up in MP games (I hear one sound, you hear another). 3do's CAN suffer from similar problems, as can MATs and KEYs. If you don't keep the count lined up (each resource is numbered) when the game calls for sound number X to be played, it may be a different sound on each client (or animation, or model, etc.). Also, the template ghost isn't in 100% of all JKLs, so it's not that great of an idea to use that template. I'd personally use a seq. charge, clear the flags that make explosions kill it, remove it's collide and maybe make it invisible, then setlifeleft with a low number but parsearg a large timer so it poofs on other people's comps, but remains on yours. I'd probably find someway to remove it's explosion as well, but too tired to think of a way to do that at the moment, probably some explode on death flag that can be cleared before it's timer expires.

[This message has been edited by Quib Mask (edited June 26, 2004).]
2004-06-26, 1:58 PM #10
DOH! Thank you.

Code:
	camlook = VectorAdd(camlook, VectorScale(VectorSub(camlook, VectorSub(GetThingPos(dummy), GetThingPos(cam))), -.15));
        SetThingLook(cam, camlook);


MMmmm, silky smooth cam.

------------------
WOOSH|-----@%

[This message has been edited by BobTheMasher (edited June 26, 2004).]
Warhead[97]

↑ Up to the top!