Gamestudio Links
Zorro Links
Newest Posts
Max Number of Strategies in /Strategy folder
by Martin_HH. 06/17/26 07:16
Z9 getting Error 058
by jcl. 06/16/26 09:51
How to select between IB accounts by script?
by AndrewAMD. 06/13/26 15:44
Zorro tutorial ideas?
by AndrewAMD. 06/13/26 15:01
Zorro 3.01 recoded MMI function issue
by 11honza11. 06/13/26 11:40
Stooq now requires an API key
by AndrewAMD. 06/11/26 17:55
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (Quad), 3,455 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Student_64151, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
[REQ[ How to smoothly turn a camera to a target? #393997
02/08/12 23:04
02/08/12 23:04
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
Greetings. I am looking to find some way to smoothly adjust my camera to a target. The player should still be able to move the camera around while locked, but once it stops moving it should return back to its target enemy. The camera should have a "max speed" as there will be some enemies which can move faster than the player can track, so when they "teleport" the camera would smoothly adjust its position.

How can I achieve this? I can post what I have so far if it would help.

Re: [REQ[ How to smoothly turn a camera to a target? [Re: exile] #393998
02/08/12 23:08
02/08/12 23:08
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
It definitely would help.


Always learn from history, to be sure you make the same mistakes again...
Re: [REQ[ How to smoothly turn a camera to a target? [Re: Uhrwerk] #393999
02/08/12 23:09
02/08/12 23:09
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
What type of camera, 1st/ 3rd person, bird's-eye view?


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: [REQ[ How to smoothly turn a camera to a target? [Re: Superku] #394001
02/08/12 23:16
02/08/12 23:16
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Yeah, post code.

Its not clear if you want the camera to MOVE toward the enemy,
or to just LOOK AT the target...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: [REQ[ How to smoothly turn a camera to a target? [Re: EvilSOB] #394105
02/10/12 04:04
02/10/12 04:04
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
Code:
function normalCamera() 
{
if(target_enemy == NULL) 
	{
	camera.pan -=  mouse_force.x * 12 * time_step;
	camera.tilt += mouse_force.y * 8 * time_step;
	camera.tilt = clamp(camera.tilt, -30, 10);
	temp = fcos(camera.tilt, -camera_distance);

	vec_set(camera.x, vector(my.x + fcos(camera.pan, temp),my.y + fsin(camera.pan, temp),my.z + 20 + fsin(camera.tilt, -camera_distance)));

	vec_diff(tempV.x, camera.x, my.x); //find the vector from the player to the camera
	vec_normalize(tempV.x, 16); //get the magnitude of it's vector to 16 quants and store it in temp
	vec_add(tempV.x, camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.

	result = c_trace(my.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS); //trace from the player to 16 quants behind the camera.
	if(result > 0) 
	{
		vec_diff(tempV.x, my.x, target.x); //find the vector from the point the trace hit to the player
		vec_normalize(tempV.x, 16); //get the magnitude of this vector to 16 quants and store in temp
		vec_set(camera.x, target.x); //place the camera at the trace hit point
		vec_add(camera.x, tempV.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
	}
}
}

function battle_cam() // 2.5D Camera
{
	var batCamZoom;
	if(target_enemy != NULL) 
	{
	vec_lerp(camCenter,my.x,target_enemy.x,0.5); 
	
	temp = fcos(camera.tilt, -autoCamera_distance);
	
	vec_set(tempV3, target_enemy.x);
	vec_sub(tempV3, my.x);
	vec_to_angle(cameraAng, tempV3);
	camera.pan = cameraAng.pan+90;
	camera.tilt = -10;

	batCamZoom = vec_dist(my.x,target_enemy.x); 
	autoCamera_distance = batCamZoom + 300;
	vec_set(camera.x, vector(camCenter.x + fcos(camera.pan, temp),camCenter.y + fsin(camera.pan, temp),camCenter.z + fsin(camera.tilt, -autoCamera_distance)));


	result = c_trace(camCenter.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS); //trace from the player to 16 quants behind the camera.
	
	DEBUG_VAR(camera.pan,10);
	if(result > 0) 
	{
		vec_diff(tempV.x, camCenter.x, target.x); //find the vector from the point the trace hit to the player
		vec_normalize(tempV.x, 16); //get the magnitude of this vector to 16 quants and store in temp
		vec_set(camera.x, target.x); //place the camera at the trace hit point
		vec_add(camera.x, tempV.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
	}
	}
}



Essentially, I would like the camera to smoothly switch between the two camera systems. Tried using vec_lerp, bot alas I am the retarded hahaha


Last edited by exile; 02/11/12 01:57.
Re: [REQ[ How to smoothly turn a camera to a target? [Re: exile] #394231
02/11/12 04:35
02/11/12 04:35
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
Sorry for the double post, but I have another problem. I am trying to have my targeting system set up where...

Player is scanning for entity
Entity gets scanned
Target indicator is created at entities position
Entity becomes outside of the scan range
Target indicator goes away.

For the life of me I cant think of a way to do this properly. Im not even sure if this would be the best way.

Click to reveal..

function scanForEnemies() //This gets called in the player loop.
{
c_scan(my.x,my.pan,vector(60,0,200),SCAN_ENTS | SCAN_LIMIT);
}

function beingTargeted() //This is the scan event
{
dvar = result;
if(targetEnt == NULL) //Prevents more than one targeting indicator being created
{
targetEnt = ent_create("target.tga",my.x,targetIcon); //Creates the Target Icon
}
}



Re: [REQ[ How to smoothly turn a camera to a target? [Re: exile] #394233
02/11/12 04:51
02/11/12 04:51
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
1st problem: Can't you set two vectors and two angles to the appropriate positions and angles?

normalCamera() calculates the vector camera_position1 (instead of camera.x) and the angle (vector) camera_angle1, the other function *_2.
Now you can easily lerp between the positions:

lerp_factor...
vec_lerp(camera.x,camera_position1,camera_position2,lerp_factor);

You may have to use ang() when you calculate camera pan from the angles.



2nd problem: I would create the target icon only once, then set it invisible when you don't need it.

ENTITY* targetMarker;
ENTITY* targetEnt;
...
targetMarker = ent_create("target.tga",...);
...
function scanForEnemies() //This gets called in the player loop.
{
targetEnt = NULL;
c_scan(my.x,my.pan,vector(60,0,200),SCAN_ENTS | SCAN_LIMIT);
if(you)
{
targetEnt = you;
reset(targetMarker,INVISIBLE);
vec_set(targetMarker.x,your.x);
}
}


Alternatively, you can set the pointer targetEnt in an event function like you currently do, e.g. as follows:

var min_dist;

function scanForEnemies() //This gets called in the player loop.
{
min_dist = 9999;
targetEnt = NULL;
c_scan(my.x,my.pan,vector(60,0,200),SCAN_ENTS | SCAN_LIMIT);
if(targetEnt)
{
reset(targetMarker,INVISIBLE);
vec_set(targetMarker.x,targetEnt.x);
}
}

function beingTargeted() //This is the scan event
{
if(result < min_dist)
{
min_dist = result;
targetEnt = me;
}
}




"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: [REQ[ How to smoothly turn a camera to a target? [Re: Superku] #394235
02/11/12 05:23
02/11/12 05:23
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
Thanks Superku, I actually figured out my second problem on my own. laugh. I just have a "being scanned" flag on my enemies. All works great now!

Re: [REQ[ How to smoothly turn a camera to a target? [Re: exile] #394236
02/11/12 07:03
02/11/12 07:03
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Try this out...

Code:
function normalCamera_2() 
{
	VECTOR target_pos;		ANGLE target_ang;	
	var move_lerp=0.25;		var ang_lerp=0.25;
	
	if(target_enemy == NULL) 
	{
		target_ang.pan  = camera.pan  - mouse_force.x * (12/ang_lerp) * time_step;
		target_ang.tilt = camera.tilt + mouse_force.y * (8/ang_lerp) * time_step;
		target_ang.tilt = clamp(target_ang.tilt , -30, 10);
		temp = fcos(target_ang.tilt , -camera_distance);
		target_ang.roll=0;
		
		target_pos.x = my.x + fcos(camera.pan, temp);
		target_pos.y = my.y + fsin(camera.pan, temp);
		target_pos.z = my.z + 20 + fsin(camera.tilt, -camera_distance);
		
		vec_diff(tempV.x, target_pos, my.x); //find the vector from the player to the camera
		vec_normalize(tempV.x, 16); 			 //get the magnitude of it's vector to 16 quants and store it in temp
		vec_add(tempV.x, target_pos); 		 //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
		
		result = c_trace(my.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS); //trace from the player to 16 quants behind the camera.
		if(result > 0) 
		{
			vec_diff(tempV.x, my.x, target.x); //find the vector from the point the trace hit to the player
			vec_normalize(tempV.x, 16); 		  //get the magnitude of this vector to 16 quants and store in temp
			vec_set(target_pos, target.x); 	  //place the camera at the trace hit point
			vec_add(target_pos, tempV.x); 	  //move the camera away from the wall by the vector temp, 16 quants towards the player
		}
		vec_lerp(camera.x,   camera.x,   target_pos, move_lerp);
		vec_lerp(camera.pan, camera.pan, target_ang, ang_lerp );
	}
}

function battle_cam_2() // 2.5D Camera
{
	VECTOR target_pos;		ANGLE target_ang;	
	var move_lerp=0.25;		var ang_lerp=0.25;
	
	var batCamZoom;
	if(target_enemy != NULL) 
	{
		vec_lerp(camCenter,my.x,target_enemy.x,0.5); 
		
		temp = fcos(camera.tilt, -autoCamera_distance);
		
		vec_set(tempV3, target_enemy.x);
		vec_sub(tempV3, my.x);
		vec_to_angle(cameraAng, tempV3);
		target_ang.pan = cameraAng.pan+90;
		target_ang.tilt = -10;
		target_ang.roll = 0;
		
		batCamZoom = vec_dist(my.x, target_enemy.x); 
		autoCamera_distance = batCamZoom + 300;
		
		target_pos.x = camCenter.x + fcos(camera.pan, temp);
		target_pos.y = camCenter.y + fsin(camera.pan, temp);
		target_pos.z = camCenter.z + fsin(camera.tilt, -autoCamera_distance);
		
		
		result = c_trace(camCenter.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS); //trace from the player to 16 quants behind the camera.
		
		DEBUG_VAR(camera.pan,10);
		if(result > 0) 
		{
			vec_diff(tempV.x, camCenter.x, target.x); //find the vector from the point the trace hit to the player
			vec_normalize(tempV.x, 16); //get the magnitude of this vector to 16 quants and store in temp
			vec_set(target_pos, target.x); //place the camera at the trace hit point
			vec_add(target_pos, tempV.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
		}
		vec_lerp(camera.x,   camera.x,   target_pos, move_lerp);
		vec_lerp(camera.pan, camera.pan, target_ang, ang_lerp );
	}
}




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: [REQ[ How to smoothly turn a camera to a target? [Re: EvilSOB] #394341
02/12/12 08:29
02/12/12 08:29
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
exile Offline OP
User
exile  Offline OP
User

Joined: Apr 2005
Posts: 796
U.S.A. Michigan
Wow EvilSOB, I wasnt expecting you to do it for me! But thanks a bunch! Its greatly appreciated. Ony problem I have is the camera goes crazy when transitioning from -180 to 180, but Im sure I can figure out how to fix that one.

Page 1 of 3 1 2 3

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

Gamestudio download | 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