Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 15,499 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Need help with first lite c project #347748
11/18/10 15:51
11/18/10 15:51
Joined: Nov 2010
Posts: 21
E
elegant_mistake Offline OP
Newbie
elegant_mistake  Offline OP
Newbie
E

Joined: Nov 2010
Posts: 21
Hi everyone. I just finished the initial tutorials. Now I am trying to slowly develop my skills by making little projects.

I have made a project with a guy that walks around in a room. I have set it so the camera follows over the shoulder of the walking guy.

Now I want to make it so that if the Alt key is pressed, the arrow buttons will move the camera around the guy but still look toward the guy, as in Secondlife.

Can anybody steer me in the right direction of how to code that? or if you have a snipped of code with comments so I can figure out how it works, that would be cool too.

Thanks. Here is my crappy little program:
//make a guy that walks around//
#include <acknex.h>


#define STATE skill1
#define ANIMATION skill2

var walk_percentage;


function main()
{

level_load("walkin_room.wmb");

}

function camera_follow(ENTITY* ent)
{
while(1)
{
vec_set(camera.x,vector(-150,10,50)); // camera position relative to the player
vec_rotate(camera.x,ent.pan); // rotate the camera position with the player
vec_add(camera.x,ent.x); // add player position
vec_set(camera.pan,vector(ent.pan,-10,0)); // look in player direction, slighty down
wait(1);
}
}




action walkA()
{
while(1)
{

my.pan += (key_cul - key_cur)*8*time_step;//make it so he can turn//

var distance = (key_cuu - key_cud)*8*time_step;
c_move(me, vector(distance,0, 0), NULL, GLIDE);//make him move forward and back//

my.ANIMATION += 2*distance;
ent_animate(me, "walkA", my.ANIMATION, ANM_CYCLE);
if (key_space)
{
ent_animate(me, "jumpA", my.ANIMATION, ANM_CYCLE);
}
camera_follow(me);
wait(1);
}
}



p.s.I am really enjoying gamestudio so far. I haven't done any programming since I packed away my old Radio Shack color computer2 about twenty-five years ago, but programming seems easier now than it did back then.


I need to come up with a better signature
Re: Need help with first lite c project [Re: elegant_mistake] #347754
11/18/10 16:42
11/18/10 16:42
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
Here you go, this will be enough for a good start I guess. Good luck.
Code:
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <acknex.h>
#include <default.c>

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

VECTOR dist;
VECTOR absdist;
VECTOR cam_set;

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

var my_height;

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

#define health skill1

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

function main()
{
	video_set(800,600,32,0);
	fps_max = 60;
	level_load("1.WMB");
	wait(1);
}

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

function handle_size(ENTITY* ent,var scale)
{
	ent.scale_x = scale;
	ent.scale_y = scale;
	ent.scale_z = scale;
}

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

function handle_camera() 
{
	camera.tilt += 10 * mouse_force.y * time_step; // turn it TILT, play with 10 for speed 
	camera.tilt = clamp(camera.tilt,-80,80); // limit cameras TILT 
	vec_set(camera.x,vector(-100,-25,70)); // place camera near right shoulder
	vec_rotate(camera.x,my.pan); // turn camera with player
	vec_add(camera.x,my.x); // add camera to player 
	if(!key_alt) // if ALT isn't pressed
	{
		camera.pan %= 360;
		camera.pan += (my.pan - camera.pan) * 1 * time_step; // turn PAN after player (play with 1)
		my.pan -= 10 * mouse_force.x * time_step; // turn players PAN
	}
	else
	{
		camera.pan %= 360;
		camera.pan -= 10 * key_force.x * time_step; // turn cameras PAN with cursors
	}
}

function handle_gravity()
{
	my_height = c_trace(my.x,vector(my.x,my.y,my.z - 1000),IGNORE_PASSABLE|IGNORE_MODELS|USE_BOX);
	if(my_height > 10)
	{
		absdist.z -= 1 * time_step;
	}
	else
	{
		absdist.z = 0;
	}
}

function handle_animation()
{
	if(key_w || key_s || key_a || key_d)
	{
		if(key_shift)
		{
			ent_animate(my,"run",my.skill48,ANM_CYCLE);
			my.skill48 += 10 * time_step;
		}
		else
		{
			ent_animate(my,"walk",my.skill48,ANM_CYCLE);
			my.skill48 += 6 * time_step;
		}
	}
	else
	{
		ent_animate(my,"stand",my.skill48,ANM_CYCLE);
		my.skill48 += 2 * time_step;
	}
}

function handle_movement()
{
	if(key_shift)
	{
		dist.x = 20 * (key_w - key_s) * time_step;
		dist.y = 20 * (key_a - key_d) * time_step;
	}
	else
	{
		dist.x = 10 * (key_w - key_s) * time_step;
		dist.y = 10 * (key_a - key_d) * time_step;
	}
}

action hero_()
{
	player = my;
	handle_size(my,1);
	my.eflags |= FAT | NARROW; 
	vec_set(my.min_x,vector(-25,-25,-60)); 
	vec_set(my.max_x,vector(25,25,60));
	my.health = 100;
	while(my.health > 0)
	{
		handle_movement();
		handle_gravity(); 
		handle_animation();
		c_move(my,dist,absdist,IGNORE_PASSABLE|GLIDE);
		handle_camera();
		wait(1);
	}
	error("YOU ARE DEAD!"); // DEATH HERE
}

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

PANEL* gui_ =
{
	layer = 4;
	digits(10,0,4,"Arial#24bi",1,player.skill1); 
	flags = SHOW;
}

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

Some screen, to show how camera is placed on shoulder:



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

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