Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
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
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (kzhao, AndrewAMD, bigsmack), 824 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Basic 3rd person camera script #122050
04/07/07 19:17
04/07/07 19:17
Joined: Aug 2006
Posts: 652
Netherlands
bstudio Offline OP
User
bstudio  Offline OP
User

Joined: Aug 2006
Posts: 652
Netherlands
this is by no means an advanced 3rd person camera script, but should get you started with the camera stuff. Any questions can be mailed to:
bas[dot]tuijnman[at]gmail.com

controls:
- just moving the mouse turns the player (and the camera)
- moving the mouse while holding the left button turns the camera
- turning the mouse wheel adjusts camera height

Here it is:
Code:

//////////////////////////////
//Camera script //
//Written by Bas Tuijnman //
//All rights reserved //
//////////////////////////////
var cam_height = 75;
var cam_height_min = 50;
var cam_height_max = 100;
var cam_behind = 75;
var cam_tilt = -45;
var cam_angle = 0;
var cam_trace;

view 3rd_person //register a new view
{
layer = 1; //place it on layer 1
pos_x = 0; //init on x pos 0
pos_y = 0; //init on y pos 0
}

function camera_init() //initialize our camer
{
camera.visible = off; //turn the standard camera off
3rd_person.size_x = screen_size.x; //make it the width of our screen
3rd_person.size_y = screen_size.y; //make it the height of our screen
3rd_person.genius = player; //attach it to the player
3rd_person.visible = on; //and turn it on
}

function check_cam() //make sure it can't go through walls
{
my = player; //i'm the player
cam_trace = c_trace(player.x,3rd_person.x,IGNORE_ME | IGNORE_PASSABLE); //trace for walls
if(cam_trace==0){return; } //if we didn't hit anything we gan go on
while(cam_trace > 0) //if we did hit something
{
3rd_person.x = player.x + cos(cam_angle)*cam_behind; //move it back
3rd_person.y = player.y + sin(cam_angle)*cam_behind; //move it back
wait(1); //wait one frame to exclude infinite loops
}
}

function control_cam() //make sure we can control it
{
while(player != null) //while the player exists
{
//place camera behind and above player
3rd_person.x = player.x - cos(cam_angle)*cam_behind;
3rd_person.y = player.y - sin(cam_angle)*cam_behind;
3rd_person.z = player.z + cam_height;

//and give it the appropriate angles
3rd_person.tilt = cam_tilt;
3rd_person.roll = player.roll;
3rd_person.pan = cam_angle;

if(mouse_force.x < 0 && mouse_right == 1) //if the mouse goes to the left and we have the right mouse button pressed
{
cam_angle -= pl_speed * time_step; //turn the camera left
}
if(mouse_force.x > 0 && mouse_right == 1) //if the mouse goes to the right and we have the right mouse button pressed
{
cam_angle += pl_speed * time_step; //turn the camera
}
if(mouse_force.x < 0 && mouse_right == 0) //if the mouse goes to the left and we don't have the right mouse button pressed
{
player.pan -= pl_speed * time_step; //turn the player
}
if(mouse_force.x > 0 && mouse_right == 0) //if the mouse goes to the right and we don't have the right mouse button pressed
{
player.pan += pl_speed * time_step; //turn the player
}
if(mickey.z > 0 && cam_height < cam_height_max) //if we turn the mouse wheel down
{
cam_height += pl_speed * time_step; //move camera up
cam_behind += pl_speed * time_step; //and more backwards
}
if(mickey.z < 0 && cam_height > cam_height_min) //if we turn the mouse wheel up
{
cam_height -= pl_speed * time_step; //move camera down
cam_behind -= pl_speed * time_step; //and more forward
}
check_cam(); //make sure we don't hit walls
wait(1); //and exclude infinite loops
}
}



to use, include this file and do this in your main script:
Code:

function main()
{
load_level("your_level.wmb");
camera_init();
wait(1);
}

action your_player_action
{
player = me;
control_cam();
}



Use it freely, credit is not needed but will be appreciated

cheers

Last edited by bstudio; 04/07/07 19:50.

BASIC programmers never die, they GOSUB and don't RETURN.
Re: Basic 3rd person camera script [Re: bstudio] #122051
04/08/07 09:07
04/08/07 09:07
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
frazzle Offline
Expert
frazzle  Offline
Expert

Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
Thxn, camera contributions are always welcome

Happy Easter ^^

Frazzle


Antec® Case
Intel® X58 Chipset
Intel® i7 975 Quad Core
8 GB RAM DDR3
SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB
NVIDIA® GeForce GTX 295 Memory 1795GB
Re: Basic 3rd person camera script [Re: frazzle] #122052
04/15/07 12:07
04/15/07 12:07
Joined: Sep 2003
Posts: 281
Arkansas\USA
raiden Offline
Member
raiden  Offline
Member

Joined: Sep 2003
Posts: 281
Arkansas\USA
Thank you bstudio. Nice contribution and very well written.

-raiden


"It doesn't matter if we win or lose, it's how we make the game."
--------------------
Links: 3DGS for Dummies
Re: Basic 3rd person camera script [Re: raiden] #122053
04/15/07 12:55
04/15/07 12:55
Joined: Aug 2006
Posts: 652
Netherlands
bstudio Offline OP
User
bstudio  Offline OP
User

Joined: Aug 2006
Posts: 652
Netherlands
No problem


BASIC programmers never die, they GOSUB and don't RETURN.

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