Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Akow, AndrewAMD), 1,640 guests, and 13 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Need help in a script #409349
10/15/12 21:08
10/15/12 21:08
Joined: Sep 2012
Posts: 16
J
JohnGillard541 Offline OP
Newbie
JohnGillard541  Offline OP
Newbie
J

Joined: Sep 2012
Posts: 16
Hi everyone, can anyone please change this first person camera script and make it into a 3rd person camera script.Please can anyone help,here is the script
///////////////////////////////////////////////////////////////////////////////////////

var camMode = -1; // 0:orbit, 1:chase, 2:cockpit, -1 disabled
var rotspd = 20; // cam movement speed
var minang = 5; // orbit between 5-70 degrees and 200-3000 quants
var maxang = 70;
var mindist = 200;
var maxdist = 3000;

var cameraTPos[3]; // camera target position
var cameraTAng[3]; // camera target angle

var temp[3];
var temp2[3];

var vecChaseOffset[3]= {-150,0,60}; // position of the camera in relation to the chassis center (chase)
var vecDriverOffset[3]= {-35,10,34}; // position of the camera in relation to the chassis center (cockpit)

var linSpeed; // car speed in XY

///////////////////////////////////////////////////////////////////////////////////////

#define KEY_CAMERA key_c // press "C" to go through the available camera modes
#define JOY_CAMERA joy_3

///////////////////////////////////////////////////////////////////////////////////////

ANGLE vecChaseAngOff; // angle of the chase camera

///////////////////////////////////////////////////////////////////////////////////////

ENTITY* pFocus; // the camera will orbit around this entity

///////////////////////////////////////////////////////////////////////////////////////

function ControlCamera_startup()
{
camera.fog_start = 1000;
camera.fog_end = 1.2 * camera.clip_far;
camera.clip_near = 25;
// init the level and wait for the focus object (we will orbit around it)
while(pFocus == NULL || camMode < 0) {wait(1);}
var cam_dist=200;
ANGLE cam_ang;
cam_ang.pan = pFocus.pan - 180;
cam_ang.tilt = 30;
cam_ang.roll = 0;
while(1)
{
while(pFocus == NULL) {wait(1);} // wait for the focus entity
if (camMode == 0) // free orbit camera?
{
reset(pFocus,INVISIBLE);
if(mouse_right) // press and hold the right mouse button to rotate the camera around
{
cam_ang.pan += rotspd * mouse_force.x;
cam_ang.tilt += rotspd * mouse_force.y;
cam_ang.tilt = clamp(cam_ang.tilt, minang, maxang);
}
cam_dist -= integer(mickey.z); // zoom using the mouse wheel
cam_dist = clamp(cam_dist, mindist, maxdist);
// find the camera location and then aim it at pFocus
camera.x = pFocus.x + cos(cam_ang.pan) * (cam_dist * cos(cam_ang.tilt));
camera.y = pFocus.y + sin(cam_ang.pan) * (cam_dist*cos(cam_ang.tilt));
camera.z = pFocus.z + sin(cam_ang.tilt) * cam_dist;
vec_set(temp,pFocus.x);
vec_sub(temp,camera.x);
vec_to_angle(camera.pan,temp);
}
if (camMode==1) // chase camera?
{
reset(pFocus,INVISIBLE);
if(mouse_right)
{
vecChaseAngOff.pan -= rotspd * mouse_force.x * time_step;
vecChaseAngOff.tilt += rotspd * mouse_force.y * time_step;
vecChaseAngOff.pan = clamp(vecChaseAngOff.pan, -20, 20);
vecChaseAngOff.tilt = clamp(vecChaseAngOff.tilt, -20, 20);
}
else
{
// return to center
if(vecChaseAngOff.pan > 0.25) {vecChaseAngOff.pan -= 2 * time_step; }
if(vecChaseAngOff.pan < -0.25) {vecChaseAngOff.pan += 2 * time_step; }
if(vecChaseAngOff.tilt > 6) {vecChaseAngOff.tilt -= 2 * time_step; }
if(vecChaseAngOff.tilt < 5) {vecChaseAngOff.tilt += 2 * time_step; }

}

vec_set(cameraTPos, vecChaseOffset); // move behind and upwards
var offset;
offset = clamp(0.01 * linSpeed * linSpeed, -100, 100);
cameraTPos[0] -= offset; // offset by speed
vec_rotate(cameraTPos, vector(ang(pFocus.pan), 0, 0));
vec_add(cameraTPos, pFocus.x);
// collide with any object in the way
c_trace(pFocus.x,cameraTPos, (IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS));
if(trace_hit == 1)
{
// offset from the target along the vector
vec_set(cameraTPos,target);
// offset from the wall along normal by the near clipping dist
vec_normalize(normal,(camera.clip_near / 2));
vec_add(cameraTPos, normal);
}
else
{
// make sure we don't clip into walls nearby
vec_diff(temp,pFocus.x, cameraTPos);
vec_normalize(temp, camera.clip_near);
vec_rotate(temp, vector(90,0,0));
vec_set(temp2, cameraTPos);
vec_add(temp2, temp); // move out by the clip_near value
c_trace(cameraTPos, temp2, (IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS));
if(trace_hit == 1)
{
// offset from that target along the vector
vec_set(cameraTPos, target);
// offset from the wall along normal by the near clipping dist
vec_normalize(normal, (camera.clip_near / 2));
vec_add(cameraTPos,normal);
}
else
{
// rotate temp back the other dir twice as much..
vec_rotate(temp, vector(-180, 0, 0));
vec_set(temp2, cameraTPos);
vec_add(temp2, temp); // move out by the clip_near value
c_trace(cameraTPos, temp2, (IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_MODELS));
if(trace_hit == 1)
{
// offset from that target along the vector
vec_set(cameraTPos, target);
// offset from the wall along normal by the near clipping dist
vec_normalize(normal, (camera.clip_near / 2));
vec_add(cameraTPos, normal);
}
}

}
// smooth out the transition
vec_diff(temp, cameraTPos, camera.x);
var vscale = clamp((time_step * 0.5), 0.001, 1);
vec_scale(temp, vscale);
vec_add(camera.x, temp);
// calc angle from camera to target...
vec_diff(temp, pFocus.x, cameraTPos);
vec_to_angle(cameraTAng, temp); // camera target angle looks at focus center
vec_add(cameraTAng, vecChaseAngOff.pan); // tweak it
// smooth out the rotation
vec_diff(temp, cameraTAng, camera.pan);
temp[0] = ang(temp[0]); // we only need the pan angle
vec_scale(temp, vscale);
vec_add(camera.pan, temp);
}
if (camMode == 2) // cockpit view?
{
vec_set(camera.pan, pFocus.pan);
vec_set(camera.x, pFocus.x);
// move to the driver side
vec_set(temp, vecDriverOffset);
vec_rotate(temp, pFocus.pan);
vec_add(camera.x, temp);
}
// toggle the camera
if (KEY_CAMERA || JOY_CAMERA)
{
while (KEY_CAMERA || JOY_CAMERA) {wait(1);} // wait until the key is released
camMode +=1; if (camMode > 2) {camMode = 0;}
// reset if previously rolled around
vec_set(camera.pan, cam_ang);
}
wait(1);
}
}

Re: Need help in a script [Re: JohnGillard541] #409355
10/15/12 22:31
10/15/12 22:31
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Firstly, why don't you use code tags? Switch to "Full Reply Screen", and search for it. Secondly, did you try to toggle cameras? As I see from some variables, there is an offset for 3rd person camera, and you should be able to toggle throw the cameras via C key.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung

Moderated by  adoado, checkbutton, mk_1, Perro 

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