PDA

View Full Version : Camera COG


GuNbOy
03-19-2003, 09:47 PM
I've been working on this camera that I want to follow around 2 characters, but have it be the side view all of the time, and when the two characters get further apart, the camera gets further away. sortof like a Tekken camera, or one of those fighting games that you have full movement in.

I have it working so that the camera's focus point is the midpoint of the two characters, and I have it so that the camera zooms in and out based on the distance between the two fighters, but when i tried to code the part so that the camera will always be perpendicular to the fighters, I got lost. this is what I have so far, and for some reason, ApplyForce() does nothing to the camera thing, while SetThingVel() seems to be using world axis instead of relative axis.

plook = VectorNorm(VectorSub(GetThingPos(victim), GetThingPos(player)));
SetThingLook(player, plook);

SetCameraFocus(0, camera);

clook = VectorSub((VectorNorm(VectorAdd(GetThingPos(player ), GetThingPos(victim)))), GetThingPos(camera));

SetThingLook(camera, clook);
pdist = VectorDist(GetThingPos(player), GetThingPos(victim));
cdist = VectorDist(GetThingPos(camera), VectorNorm(VectorAdd(GetThingPos(player), GetThingPos(victim))));
cross = VectorCross(GetThingLVec(camera), VectorNorm(VectorSub(GetThingPos(player), GetThingPos(victim))));
SetThingVel(camera, VectorSet(VectorX(cross)*10, VectorY(GetThingLVec(camera))*(cdist-pdist)*10, 0));

Printvector(cross);


I tried using VectorCross as a means of knowing if the camera is offset to the right or left, but I dont think it is working properly...Then again, it could jus be that it is making the velocity be in world axis, but I was under the impression that SetThingVel() used relative axis.

Does anyone know why applyForce won't budge the camera at all? while SetThingVel just goes crazy?

If anyone knows of an easier way to do this, it would be very helpfull

I hope t hat wasn't too confusing....

------------------
I'm just an old man with a skooma problem.

GuNbOy
03-19-2003, 09:51 PM
oh, in the SetThingVel() line, the y part of the vector is the part that controls the zooming in/out, this part works by itself, but once i added the cross product value in there, it went crazy. I was just trying stuff out, the specs are pretty vague on the vector commands, and I am not the best at vector math.

------------------
I'm just an old man with a skooma problem.

LordVirus
03-21-2003, 05:41 AM
ApplyForce() probably won't work on the camera because of the move entry in the template (I think). Try changing it to "move=physics".

I was never very good at vector math myself. But do you want the camera to always stay to one side of the players, rotating based on direction? Or do you mean when you attach it to the player's left/right motion?
------------------
His pot is blacker than his kettle!

Phoenix Swords (http://www.phoenixswords.com)

[This message has been edited by LordVirus (edited March 21, 2003).]

GuNbOy
03-21-2003, 05:36 PM
Actually, the camera didn't move at all even with SetThingVel(); when I had originally just used a ghost object, so I changed it to move=physics and it worked, but only with SetThingVel();, not ApplyForce();. So it is move=physics now.

As for the position of the camera, I want it to move based on the position of the two contenders. In other words, the camera should be positioned so that it is perpendicular to the line made by using the characters as end points. like this: |-

where | is the line made by the characters and - is the line made by the camera and the midpoint of |.

------------------
I'm just an old man with a skooma problem.

[This message has been edited by GuNbOy (edited March 21, 2003).]

LordVirus
03-22-2003, 05:49 AM
Okay, you may want to look at the flags on the Throwcrate, because I believe ApplyForce() affects that.

As to the vector math... Hmm. The vector math you have there already goes somewhat beyond my limited capabilities. Perhaps if you VectorSub() the two positions, take the Z axis (I think, I believe Z is forward/back, and not up/down) using VectorZ(), divide it by two, and then make a new vector, using something like:

PosVec=VectorSub(GetThingPos(player1), GetThingPos(player2));
ZVec=VectorZ(PosVec)/2;
CamPos=VectorSet(VectorX(*Put Zoom Distance Here*), VectorY(GetThingPos(player1)),VectorZ(GetThingPos( player1))+ZVec);
SetThingPos(camera, CamPos);


No idea if this would work or not. My vector math skills suck, and I can't test it.

------------------
His pot is blacker than his kettle!

Phoenix Swords (http://www.phoenixswords.com)

SaberMaster
03-22-2003, 06:28 AM
Try this:


# fightcam.cog
#
# A camera cog for duel fighting.
#
# [SM]
#================================================= =============#
symbols

thing player local
thing cam local
thing enemy

template camTpl

flex dist local

vector lvec local
vector lvec2 local
vector lvec3 local
vector midpos local
vector rightVec local
vector upVec local
vector offset local
vector campos local

message startup
message pulse
message killed
message removed

end
#================================================= =============#
code
#------------------------------------------------------
startup:
Sleep(1);
player=GetLocalPlayerThing();
cam=CreateThing(camTpl, player);
SetCameraFocus(1, cam);
SetPulse(0.05);

Return;
#------------------------------------------------------
pulse:
dist=VectorDist(GetThingPos(player), GetThingPos(enemy));
lvec=VectorNorm(VectorSub(GetThingPos(enemy), GetThingPos(player)));
midpos=VectorAdd(GetThingPos(player), VectorScale(lvec, dist/2));

rightVec=VectorScale(VectorScale(VectorCross(GetTh ingUVec(player), lvec), -1), dist/2);
upVec=VectorScale(GetThingUVec(player), dist/5);
offset=VectorAdd(rightVec, upVec);
campos=VectorAdd(midpos, offset);

dist=VectorDist(GetThingPos(cam), campos);
lvec2=VectorNorm(VectorSub(campos, GetThingPos(cam)));
SetThingVel(cam, VectorScale(lvec2, dist*2));

lvec3=VectorCross(GetThingUVec(player), lvec);
SetThingLook(cam, lvec3);

Return;
#------------------------------------------------------
killed:
removed:
SetPulse(0);
SetCameraFocus(1, player);
DestroyThing(cam);

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

with a template of:

camtemp none orient=(0/0/0) type=weapon move=physics size=0.05 movesize=0.05 collide=1 physflags=0x2 mass=1

That will work well, but the camera movement doesn't seem to be fine enough - that could use work, but it should do everything you want. http://forums.massassi.net/html/wink.gif

------------------
Author of the JK DataMaster (http://www.geocities.com/sabersdomain/fileframe.html), Parsec (http://www.geocities.com/sabersdomain/fileframe.html), Scribe (http://www.geocities.com/sabersdomain/fileframe.html), and the EditPlus Cog Files (http://www.geocities.com/sabersdomain/fileframe.html).

[This message has been edited by SaberMaster (edited March 22, 2003).]

GuNbOy
03-22-2003, 12:09 PM
Thanks saber master, this is exactly what I wanted! I need to change a few things, but this is great. thanks.

------------------
I'm just an old man with a skooma problem.

GuNbOy
03-22-2003, 01:05 PM
Yeah, the movement gets really jerky when you jump. I've been trying to fix it, but every time I try something it just screws up and goes crazy. Also, I need the camera to be further away from the characters; as it is now, you can see only half of each player. But again when I tried to fix that it just went crazy again. http://forums.massassi.net/html/frown.gif

------------------
I'm just an old man with a skooma problem.

[This message has been edited by GuNbOy (edited March 22, 2003).]

zagibu
03-22-2003, 01:45 PM
Wow, your post count in hexnumbers looks really bad at the moment. Anyway, Master will come soon and help you. He's really back.

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

SaberMaster
03-23-2003, 10:25 PM
If it's too jerky, then the pulse needs to run more quickly. 0.05 is too slow - make it something like 0.01. As for the camera distance, change 'dist/2' in the rightvec= line to 'dist/1.7' or whatever you want.

As it is, the camera takes a little time to adjust - the player/NPC may move off of the screen. To fix that, just increase the camera's velocity. Change 'dist*2' to 'dist*4' or what-have-you.

Good luck. http://forums.massassi.net/html/wink.gif

------------------
Author of the JK DataMaster (http://www.geocities.com/sabersdomain/fileframe.html), Parsec (http://www.geocities.com/sabersdomain/fileframe.html), Scribe (http://www.geocities.com/sabersdomain/fileframe.html), and the EditPlus Cog Files (http://www.geocities.com/sabersdomain/fileframe.html).

Hell Raiser
03-24-2003, 09:56 AM
Bah! I showcase TDiR Melee and everyone wants to make a 3d fighter mod. http://forums.massassi.net/html/tongue.gif http://forums.massassi.net/html/smile.gif

I don't mean to gloat, I've got the fighter type camera perfected. http://forums.massassi.net/html/smile.gif It even stays in place when you jump over a player. (they switch sides, but the camera stays) It's pretty versitile in being able to keep up with fast paced fighting. If you need help or are just interested in the cog altogether, gimmie a holler on the holonet server at #dbztdir http://forums.massassi.net/html/smile.gif

------------------
-Hell Raiser
Remember kiddies, trial and error.
Without struggles there is no progress
DBZ: The Destruction is Real (http://tdir.hellraiser64.com)

GuNbOy
03-24-2003, 12:26 PM
Thanks SaberMaster.

Hell Raiser, I know it certainly looks like im just ripping off TDIR, but I have had this idea for so long, you just inspired me to take action. I'll drop by if I need help http://forums.massassi.net/html/biggrin.gif

------------------
I'm just an old man with a skooma problem.