function moveCamera() {

Posted By: NiceOneX

function moveCamera() { - 08/31/16 15:04

Hey guys smile ,
I'm new here in the forum and would like to learn how to programiert games. grin
I bought a book that something helps me. However, I have the same at the beginning a problem with my script ...

Although the level loads but the function with the camera can not be performed. I thank you in advance for the help.

and sorry for my bad english tired


Script:
Code:
#include <acknex.h>
#include <default.c>

#define WALK_SPEED 5

function moveCamera() {
	
	VECTOR* vecNewAngle = NULL;
	VECTOR* vecNewPosition = NULL;
	
	while(1) {
		vecNewAngle = vector(
			(camera.pan+(key_a-key_d)*time_step*WALK_SPEED)%360,
				0,
				0
			);
		
		vec_set(camera.pan,vecNewAngle);
		
		vecNewPosition = vector(
		camera.x+(key_w-key_s)*cosv(camera.pan)*time_step*WALK_SPEED,
		camera.y+(key_w-key_s)*sinv(camera.pan)*time_step*WALK_SPEED,
		0
		);
		
		vec_set(camera.x, vecNewPosition);
		
		wait(1);	
	}
}

function main() {
	level_load("terrain1.hmp");
	VECTOR* vecPosition = vector(0,0,0);
	ent_create("world1.mdl",vecPosition,NULL);
	moveCamera();
}


Posted By: rayp

Re: function moveCamera() { - 08/31/16 15:26

Hi and welcome on board.

The code itself seams to be ok ( i mean it runs without errors )

Create a Terrain (HMP) and a model file (MDL). Both with MED. Then your script will run. Pretty sure it cant load one of those files.

Or create a simple map (WMB) with WED. And modify your main function like this
Code:
function main() {
	level_load("yourlevel.wmb");

	moveCamera();
}



Guess problem now is your script / game cant found those files loaded from here
Code:
level_load("terrain1.hmp");
ent_create("world.mdl",vecPosition,NULL);



edit:
If you write your code here in the forum between [ c o d e ] and [ / c o d e ] but without the empty spaces your text will appear in a codebox and will be much more easy to read grin

edit2:
I made another very simple example. Create a map with WED. For example just a hollowed block. Save it as "yourlevel.wmp". Build the map ( will create the WMB file ).
Create a new script file with the following code
Code:
#include <acknex.h>
#include <default.c>

#define WALK_SPEED skill1   // mask skill1 of ent with WALK_SPEED
#define HEALTH     skill2   // same here but with health and skill2


action simpleHero(){        // actions will apear in the WED action list of your script
	my.WALK_SPEED = 6;       // set our speed 
	my.HEALTH     = 100;     // 100 lifepoints
	VECTOR dist;             // a vector for distance ent is moving
	while (my.HEALTH > 0){   // as long as weve lifepoints were looping the code below
		dist.x = ((key_w - key_s) * my.WALK_SPEED) * time_step; // forward backward moving
		dist.y = ((key_a - key_d) * my.WALK_SPEED) * time_step; // side moving
		move_mode = IGNORE_ME | IGNORE_PASSABLE | GLIDE;        // used from c_move below
		c_move (me, vector (dist.x, dist.y, 0), nullvector, move_mode); // finally move the ent!
		my.pan -= mickey.x * time_step;		 // handle PAN of entity ( left - right looking )
		vec_set (camera.x, my.x);            // set camera XYZ to entitys XYZ (follow)
		camera.pan = my.pan;                 // set camera PAN to ent pan
		camera.roll = 0;
		camera.tilt -= mickey.y * time_step; // handle camera TILT ( up - down looking )
		camera.tilt = clamp (camera.tilt, -85, 85); // clamp the camera TILT value
		wait (1); // wait one frame
	}
}

void main() {
	level_load("yourlevel.wmb"); // load the level created in WED
	ent_create("player.mdl", vector (0,0,0), simpleHero); // load your hero / player
	// needs two files in the folder: yourlevel.wmb and your player entity player.mdl
}



Greets

Posted By: NiceOneX

Re: function moveCamera() { - 08/31/16 15:56

I'm already so many things tried. but every time loads only the level but the camera still does not move with the keys goes. =/
Posted By: rayp

Re: function moveCamera() { - 08/31/16 16:03

When i tested the function first, i only saw a blue Screen / sky caused by the empty placeholder models i used. Try with a hollowed block created in WED. Pretty sure with the code is everything ok.

edit: Or try my example, maybe it fit what you Needs.
Posted By: NiceOneX

Re: function moveCamera() { - 08/31/16 16:18

okay thanks for the help, I'll try it this way =)
Posted By: rayp

Re: function moveCamera() { - 08/31/16 16:23

No problem you are welcome. Good luck. wink
Posted By: Reconnoiter

Re: function moveCamera() { - 09/02/16 10:01

Hi NiceOneX welcome to do the forum.
Since your new; incase you want better shaders (/better graphics) for your game you may want to take a look at 'Shade-C EVO' on this forum or on Github.
That is a package that you can include in your script and which gives access to improved hdr, normal mapping, ssao etc.
You could basically see it as an upgrade over Gamestudio graphics wise.
Here is an usefull thread that you should rease incase you are going to use it and/or get stuck (you can also ask questions there): http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=461868&page=1
© 2024 lite-C Forums