Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (dr_panther, TedMar, AndrewAMD), 986 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Over shoulder camera #352128
01/01/11 06:30
01/01/11 06:30
Joined: Jul 2009
Posts: 85
A
Altarius Offline OP
Junior Member
Altarius  Offline OP
Junior Member
A

Joined: Jul 2009
Posts: 85
Hi,

Anyone know how to modify this code for change the position of the camera relatively to player?

camera.x = my.x + fcos((camera.pan),cam_focus);
camera.y = my.y + fsin((camera.pan),cam_focus);
camera.z = my.z+60 + fsin(camera.tilt,cam_dist);

I want to make a 3rd person camera 'over shoulder' like in Gear of war, Spinter Cell...ect , where's the camera are placed a little from right of the player.

I tried to add a value (-35) like that:

camera.y = my.y - 35 + fsin((camera.pan),cam_focus);

But now the camera dont pan correctly whit the player model...

I know there's other way to code a camera like that but i want too know if its possible to just add something to this code for get it work.

Thx

Last edited by Altarius; 01/01/11 06:31.
Re: Over shoulder camera [Re: Altarius] #352131
01/01/11 09:14
01/01/11 09:14
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline
Serious User
Rackscha  Offline
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
okay, youre just right here laugh

to calculate an offset(iam just doing the offset, bobing/shaking) will be yours ;))
we will simply set an offset and rotate it. here we go:

Code:
VECTOR Offset;

function DoCam()
{
  Offset.x = -50;//50 units behind
  Offset.y = 10; //10 units to the right
  Offset.z = 50;//50 units up
  vec_rotate(Offset, my.pan);
  //now you can simply add this rotated offset to the player position to get
  //the offset point. Your code should work if you do this(hopefully):
  camera.x = my.x + Offset.x + fcos((camera.pan),cam_focus);
  camera.y = my.y + Offset.y + fsin((camera.pan),cam_focus);
  camera.z = my.z+6 Offset.z + fsin(camera.tilt,cam_dist);
}



Ofcourse you have to adjust my offset values to fit your setting wink.

Hope this works, havent tried, just rewritten from Memories.

If somethings not working, fell free to ask.

Greets
Rackscha


MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Re: Over shoulder camera [Re: Rackscha] #352175
01/01/11 19:42
01/01/11 19:42
Joined: Dec 2010
Posts: 8
S
SQS Offline
Newbie
SQS  Offline
Newbie
S

Joined: Dec 2010
Posts: 8
I programmed a camera like this a few days ago, but I deleted the file... so it's not tested, sry ^^

Code:
var distance = 100; //distance between the player and the camera

function players_camera()
{
  camera.x = my.x - distance*cos(20+my.pan);
  camera.y = my.y - distance*sin(20+my.pan);
  camera.z = my.z;
}



The idea was to change the angle used for the position to move the camera around the player a little bit, til it's on the right side of him.
But this is A7 and when I look at your codes it seems there is no "normal" sinus-Function anymore... grin Maybe you have to change it a little bit, shouldn't be a problem, if you understand my explanation although it is not good xD (if not, feel free to ask)
Just play with the 100 and 20 til the position is ok.

Re: Over shoulder camera [Re: SQS] #352177
01/01/11 19:59
01/01/11 19:59
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
Code:
vec_set(temp,vector(-256,-32,64));
		vec_rotate(temp,vector(camera.pan,cam_angle,0));
		vec_add(temp,my.x);
		vec_set(camera.x,temp);
		
		if(c_trace(my.x,camera.x,IGNORE_MODELS | IGNORE_PASSABLE | IGNORE_PASSENTS | IGNORE_ME))
		{
			vec_set(camera.x,target);
			vec_add(camera.x,normal);
		}



maybe this is what you need
i used it in a GTA "clone" grin


Visit my site: www.masterq32.de
Re: Over shoulder camera [Re: MasterQ32] #352764
01/05/11 19:53
01/05/11 19:53
Joined: Sep 2009
Posts: 84
Theil Offline
Junior Member
Theil  Offline
Junior Member

Joined: Sep 2009
Posts: 84
Try something like this:

//Basic player movement
vec_set(temp.x, my.x);
temp.z -= 10000;
temp.z = -c_trace (my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE | USE_BOX) - 2;
temp.x = 50 * (key_w - key_s) * time_step;
temp.y = 50 * (key_a - key_d) * 0.6 * time_step;
c_move (my, temp.x, nullvector, IGNORE_PASSABLE | GLIDE | USE_BOX);

my.pan -= 50 * mouse_force.x * time_step;
camera.pan -= 50 * mouse_force.x * time_step;
camera.tilt += mouse_force.y * 8 * time_step;
camera.tilt = clamp(camera.tilt,-20,40);//30.10
cam_z -= mouse_force.y * 8 * time_step;
cam_z = clamp(cam_z,5,60);//30.10

//cam_z for moving the camera up and down when looking with the mouse
//-106 the distance from the cam to the player
//-16 position the camera on the right side, left side should be 16
//play around with this values
vec_set(temp2,vector(-106,-16,cam_z));
vec_rotate(temp2,vector(camera.pan,10,0));
vec_add(temp2,my.x);
vec_set(camera.x,temp2);


if(c_trace(my.x,camera.x,IGNORE_MODELS | IGNORE_PASSABLE | IGNORE_PASSENTS | IGNORE_ME))
{
vec_set(camera.x,target);
vec_add(camera.x,normal);
}

Edit: I already tested the code and it worked, take a look and tell me if this is what you need.



Last edited by Theil; 01/05/11 20:05.
Re: Over shoulder camera [Re: Theil] #352774
01/05/11 20:55
01/05/11 20:55
Joined: Aug 2009
Posts: 1,438
Spain
painkiller Offline
Serious User
painkiller  Offline
Serious User

Joined: Aug 2009
Posts: 1,438
Spain
You can also use this one:
Code:
var camera_tilt=0;
function camera_3rdperson(ENTITY* ent,VECTOR* offset)
{
        var factor=1;
	VECTOR camera_x;
	if (!ent) return;
	vec_set(camera_x,offset);
	vec_rotate(camera_x,vector(ent.pan, camera_tilt+ent.tilt, 0));
	vec_add(camera_x,ent.x);
	vec_set(camera.x,camera_x);
	vec_set(camera.pan,vector(ent.pan,ent.tilt*factor+camera_tilt*factor,ent.roll*factor));
}



you have to call it in a loop:

Code:
while(1)
{
		camera_tilt+= mouse_force.y;
		camera_person(player,vector(-tcamera_dist,tcamera_offset_y,tcamera_height),1);

wait(1);
}



Last edited by painkiller; 01/05/11 23:32.

3D Gamestudio A8 Pro
AMD FX 8350 4.00 Ghz
16GB RAM
Gigabyte GeForce GTX 960 4GB
Re: Over shoulder camera [Re: painkiller] #352886
01/06/11 14:23
01/06/11 14:23
Joined: Aug 2003
Posts: 127
Berlin, Germany
C
CHaP Offline
Member
CHaP  Offline
Member
C

Joined: Aug 2003
Posts: 127
Berlin, Germany
Oh great. This thread is exactly what I need.
I will add a offset at my camera too but there is no clue for me how I can make this done.

So, here it is:
(it is a standart 3rd person view)

Code:
//////////////////////////////////////////////////////////////////////////////////////////////
void CAMERA_calculate()
{
	while(1)
	{
		cameraContainer.currentDistance = (cos(cameraContainer.eulerTilt) * cameraContainer.totalDistance);
		camera.x = (cameraContainer.pivotX  - cos(cameraContainer.eulerPan) * cameraContainer.currentDistance);
		camera.y = (cameraContainer.pivotY - sin(cameraContainer.eulerPan) * cameraContainer.currentDistance);
		camera.z = (cameraContainer.pivotZ  + sin(cameraContainer.eulerTilt) * cameraContainer.totalDistance);
		camera.pan = cameraContainer.eulerPan;
		camera.tilt = -(cameraContainer.eulerTilt);
		camera.roll = 0;
		wait(1);
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////



The cameraContainer contains all the informations about the player like xyz and pan/tilt.

It would be nice if anybody can help me and Altarius, feel free to copy this code and use it for yourself (if it works of course) grin

Re: Over shoulder camera [Re: CHaP] #352952
01/06/11 19:31
01/06/11 19:31
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline
Serious User
Rackscha  Offline
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
Set an offset, look at my code at the top wink


MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Re: Over shoulder camera [Re: Rackscha] #352959
01/06/11 20:13
01/06/11 20:13
Joined: Aug 2003
Posts: 127
Berlin, Germany
C
CHaP Offline
Member
CHaP  Offline
Member
C

Joined: Aug 2003
Posts: 127
Berlin, Germany
@Rackscha: Yap, this is what I have tried at first. But the offset works not correctly. If I rotate the player, the camera will move around in a kind of ellipse.

Code:
//////////////////////////////////////////////////////////////////////////////////////////////
void CAMERA_calculate()
{
	VECTOR vecOffset;
	while(1)
	{
		vecOffset.x = 0;
  		vecOffset.y = 50;
  		vecOffset.z = 0;
  		vec_rotate(vecOffset,cameraContainer.eulerPan);
  		cameraContainer.currentDistance = (cos(cameraContainer.eulerTilt) * cameraContainer.totalDistance);
		camera.x = (cameraContainer.pivotX + vecOffset.x - cos(cameraContainer.eulerPan) * cameraContainer.currentDistance);
		camera.y = (cameraContainer.pivotY + vecOffset.y - sin(cameraContainer.eulerPan) * cameraContainer.currentDistance);
		camera.z = (cameraContainer.pivotZ + vecOffset.z + sin(cameraContainer.eulerTilt) * cameraContainer.totalDistance);

		// also this
		camera.x = (cameraContainer.pivotX + vecOffset.x + fcos(cameraContainer.eulerPan) * cameraContainer.currentDistance);
		camera.y = (cameraContainer.pivotY + vecOffset.y + fsin(cameraContainer.eulerPan) * cameraContainer.currentDistance);
		camera.z = (cameraContainer.pivotZ + vecOffset.z + fsin(cameraContainer.eulerTilt) * cameraContainer.totalDistance);


		camera.pan = cameraContainer.eulerPan;
		camera.tilt = -(cameraContainer.eulerTilt);
		camera.roll = 0;
		wait(1);
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////



maybe wrong place?!

Re: Over shoulder camera [Re: CHaP] #352962
01/06/11 20:57
01/06/11 20:57
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline
Serious User
Rackscha  Offline
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
yust do this small steps:

1) rotate the offset by the PLAYER angle.
2) add the player position to the offset.
3) the result of 2) is the neede camera position
4) your camera is now at its perfect position, yust give it the same pan/tilt as the player

Last edited by Rackscha; 01/06/11 20:58.

MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1