Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, dr_panther), 821 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Need help tweaking this old camera code for A7 #267775
05/26/09 08:04
05/26/09 08:04
Joined: Feb 2002
Posts: 288
California, USA
J
jaknine Offline OP
Member
jaknine  Offline OP
Member
J

Joined: Feb 2002
Posts: 288
California, USA
Can anyone add the few things needed to make this older C-script code work with A7? It's code I used for a cut camera system on an old game and it worked great for it. I'm trying to use it in a new project but it keeps throwing up errors because of some deprecated commands. I have a feeling it's a fairly simple thing to change it but I've tried a bunch of things and for some reason I just can't get it to work in A7.

Basically the code does this...

There's a dummy object that serves as the camera, and it always faces towards a center point. There are several paths in the level and when a key is pressed the camera jumps to the given path and travels around it.

The buggy stuff happens where it determines the waypoints. All that path stuff has changed over the years and this old way of doing it doesn't work anymore.

So, any help making this work in A7 would be appreciated, and I am happy to pay for a fix if someone can get it working within a day or two.

Thanks!

Code:
// don't forget to "include" this file
// attach action cutcamera_init to an entity

view cutcamera{}

var cut_center;
var max_speed = 4;

var counter = 99;
var timeslow = 0;


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
action cutcamera_init // attach it to dummy.mdl, etc.
{

clip_size = 0; // render all the triangles for all the models

vec_set (cut_center, my.pos); // store the (relative) center values
my.skill20 = max_speed; // store the speed

my.invisible = on;
my.passable = on;

camera.visible = off; // disable "camera" view

cutcamera.tilt  = -5; // look down a bit
cutcamera.pos_x = 0;
cutcamera.pos_y = 0;
cutcamera.size_x = screen_size.x;
cutcamera.size_y = screen_size.y;
ent_path("pathfly"); // follow this path
ent_waypoint(my._target_x, 1); // store first waypoint 

my.x = my._target_x; // start from the first waypoint
my.y = my._target_y;
my.z = my._target_z;

wait(4);
cutcamera.visible = on; // make cutcamera visible


while(1)
{

	cutcamera.x = my.x;
	cutcamera.y = my.y;
	cutcamera.z = my.z;
	cutcamera.pan = my.pan;

	// follow path -> set _speed
	vec_set(my._speed, my._target_x);
	vec_sub(my._speed, my.x); 

	// don't get too close to the target -> find next waypoint
	if (vec_to_angle(my.pan, my._speed) < 15)
	{
		ent_nextpoint(my._target_x);
	} 

	// turn the camera towards its center (cut_center)
	vec_set (temp, cut_center.x);
	vec_sub (temp, my.x);
	vec_to_angle (my.pan, temp); 

	vec_normalize(my._speed, (max_speed * time)); // normalize _speed

/////////////////////// KEYS ////////////////////////

	if (key_s != 1) // press "S" to stop the movement
	{
		ent_move(nullskill, my._speed); 
	}

	if (key_1 == 1) // press "1" to freeze the current view
	{
		cutcamera.x = my.x;
		cutcamera.y = my.y;
		cutcamera.z = my.z;
		cutcamera.pan = my.pan;
		ent_move(nullskill, my._speed);
		max_speed = 0;
		my.skill20 = max_speed; // store the speed
	}

	if (key_2 == 1) // press "2"
	{
		camera.visible = off; // disable "camera" view
		cutcamera.visible = on; // make cutcamera visible
		ent_path("campathround"); // follow this path
		cutcamera.tilt = -14; // look down a bit
		max_speed = 6;
		my.skill20 = max_speed; // store the speed
	}

	if (key_3 == 1) // press "3"
	{
		camera.visible = off; // disable "camera" view
		cutcamera.visible = on; // make cutcamera visible
		ent_path("pathfly"); // follow this path
		cutcamera.tilt = -5; // look down a bit
		max_speed = 4;
		my.skill20 = max_speed; // store the speed
	}

	if (key_4 == 1) // press "4"
	{
		camera.visible = off; // disable "camera" view
		cutcamera.visible = on; // make cutcamera visible
		ent_path("campathroundbig"); // follow this path
		cutcamera.tilt = -10; // look down a bit
		max_speed = 7;
		my.skill20 = max_speed; // store the speed
	}

	if (key_5 == 1) // press "5"
	{
		camera.visible = off; // disable "camera" view
		cutcamera.visible = on; // make cutcamera visible
		ent_path("campathwide"); // follow this path
		cutcamera.tilt  = -2;
		max_speed = 7;
		my.skill20 = max_speed; // store the speed
	}

	if (key_6 == 1) // press "6"
	{
		camera.visible = off; // disable "camera" view
		cutcamera.visible = on; // make cutcamera visible
		ent_path("upperpath"); // follow this path
		cutcamera.tilt  = -12;
		max_speed = 3;
		my.skill20 = max_speed; // store the speed
	}

	if (key_7 == 1) // press "7"
	{
		camera.visible = off; // disable "camera" view
		cutcamera.visible = on; // make cutcamera visible
		ent_path("campath1"); // follow this path
		cutcamera.tilt = -10; // look down a bit
		max_speed = 3;
		my.skill20 = max_speed; // store the speed
	}

	if (key_8 == 1) // press "8"
	{
		camera.visible = off; // disable "camera" view
		cutcamera.visible = on; // make cutcamera visible
		ent_path("highcam"); // follow this path
		cutcamera.tilt = -30; // look down a bit
		max_speed = 5;
		my.skill20 = max_speed; // store the speed
	}

	if (key_9 == 1) // press "9"
	{
		camera.visible = off; // disable "camera" view
		cutcamera.visible = on; // make cutcamera visible
		ent_path("undercam"); // follow this path
		cutcamera.tilt = 30; // look down a bit
		max_speed = 5;
		my.skill20 = max_speed; // store the speed
	}

	if (key_a == 1) // press "a" to turn on regular "free" camera
	{
		camera.visible = on; // enable "camera" view
		cutcamera.visible = off; // make cutcamera invisible

	}	

// add some spices
	if (my.z < 190) // get this value in wed
	{
		max_speed = max (my.skill20 / 2, max_speed * 0.995);  
	}
	else
	{
		max_speed = min (my.skill20, max_speed * 1.005);
	}
	wait(1);
} 
}



Re: Need help tweaking this old camera code for A7 [Re: jaknine] #267785
05/26/09 08:40
05/26/09 08:40
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Paste this in at the top.
Its not old c-script issues, its old A6-template defines...
Code:
// for actor entities, and for doors and platforms
DEFINE _TARGET,SKILL17;
DEFINE _TARGET_X,SKILL17;
DEFINE _TARGET_Y,SKILL18;
DEFINE _TARGET_Z,SKILL19;
DEFINE _SPEED,SKILL11; 
DEFINE _SPEED_X,SKILL11;
DEFINE _SPEED_Y,SKILL12;
DEFINE _SPEED_Z,SKILL13;

I cant say I really tested it, but it now compiles and runs without errors.
(A7.77 commercial)


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Need help tweaking this old camera code for A7 [Re: EvilSOB] #267791
05/26/09 09:23
05/26/09 09:23
Joined: Feb 2002
Posts: 288
California, USA
J
jaknine Offline OP
Member
jaknine  Offline OP
Member
J

Joined: Feb 2002
Posts: 288
California, USA
Thanks for the help, that does indeed get it to compile. The main problem I'm having is that the dummy object I have assigned as the cutcamera doesn't follow the path. It just sits there.

I think that's where the old code is failing, because things like "ent_nextpoint(my._target_x);" for finding the next waypoint no longer do anything in A7. All of those commands have been replaced with "path" commands and it's with those that I'm having trouble doing the translation.

I did manage to try a few newer commands in place of the old ones in various places and got the dummy to at least follow some path and it even keeps its angle facing toward the center (I was watching the object in the level with a free camera) but the camera view itself isn't working.

I'll keep fiddling with it but thanks again for covering the DEFINES. smile

Re: Need help tweaking this old camera code for A7 [Re: jaknine] #267912
05/26/09 19:35
05/26/09 19:35
Joined: Feb 2002
Posts: 288
California, USA
J
jaknine Offline OP
Member
jaknine  Offline OP
Member
J

Joined: Feb 2002
Posts: 288
California, USA
Ok I have it working now. I ended up using a combination of this code and some newer code for objects following paths. The camera flies on the path and keeps the target in view. All I have to do now is smooth out the motion so it's not jerky.


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

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