Solved Move camera during game

Question that is answered or resolved.

dantedevil

Well-known member
I wanna know if possible change the camera offset during game.
I'm working in a new stage with a deep hole with spikes. So the idea is throw an enemy therw , then the enemy fall in the hole and the camera follow all the fall until he is killed by the spikes, during this all other characters in the screen must be freezed. Then the camera return to the normal position and the game play normally again.
 
dantedevil said:
I wanna know if possible change the camera offset during game.
I'm working in a new stage with a deep hole with spikes. So the idea is throw an enemy therw , then the enemy fall in the hole and the camera follow all the fall until he is killed by the spikes, during this all other characters in the screen must be freezed. Then the camera return to the normal position and the game play normally again.

use:
changelevelproperty("cameraxoffset",VALUE);
changelevelproperty("camerazoffset",VALUE);

with changelevelproperty("scrollspeed",VALUE);

please use these funcs with
if ( openborvariant("in_level") ) {
... . . . . .
}
 
So where will the functions be placed at? In player txt or level txt? Or in the script file?

I haven't tested the cam offset but just to see if it could work or not:

Code:
if(openborvariant("in_level")){
  changelevelproperty("cameraxoffset", 7); //X offset for camera
  changelevelproperty("camerazoffset", 19); //Z offset for camera
  changelevelproperty("scrollspeed", 10); //Scrolling camera?
}

EDIT: Corrected the code. I missed the last parenthesis for the main if.
 
Thanks my friends!
I think in the player txt is the best option.
Because you can set in the beginning of the animation,  and after you can set in the end of animation again, to return the camera to the normal position.
 
Code:
if(openborvariant("in_level"){
  changelevelproperty("cameraxoffset", 7); //X offset for camera
  changelevelproperty("camerazoffset", 19); //Z offset for camera
  changelevelproperty("scrollspeed", 10); //Scrolling camera speed
}


for example in  updatescript event in a level#.txt file
or in an entity script event if you want  ;)
 
or in an entity script event if you want 

Can you show me a example about this?

My idea is use the first camera move to follow the enemy during fall.

Something lke this:

anim fall33
Delay 20
landframe 3
Offset 82 177
frame data/chars/bd1/fall1.png
frame data/chars/bd1/fall2.png
HERE THE CAMERA SCRIPT
Delay 999
frame data/chars/bd1/fall3.png
Delay 10
frame data/chars/bd1/fall4.png

Then after the death animation, use the script to return the camera to the normal position.

Anim death33
Delay 12
Offset 82 177
frame data/chars/bd1/fdeath1.png
frame data/chars/bd1/fdeath2.png
frame data/chars/bd1/fdeath3.png
HERE THE CAMERA SCRIPT
frame data/chars/bd1/fdeath4.png

So this is possible?
 
script event is:
script    your_script.c // in your entity.txt file

but if you want to put between frames use:
animationscript    your_script.c

then use the func:
void scrollcam(float xoff, float zoff, float spd) {
  if( openborvariant("in_level") ) {
    changelevelproperty("cameraxoffset", xoff); //X offset for camera
    changelevelproperty("camerazoffset", zoff); //Z offset for camera
    changelevelproperty("scrollspeed", spd); //Scrolling camera speed
  }
}
 
Test, but not working.

Here the error log:
Code:
Script error: data/chars/ryu/ryu.txt, line 564: Invalid declaration(expected comma, semicolon or initializer?) '(' (in production 'decl')

void scrollcam(float xoff, float zoff, float spd) {
              ^

Identifier expected before 'float'.


Script error: data/chars/ryu/ryu.txt, line 564: Invalid declaration(expected comma, semicolon or initializer?) 'float' (in production 'decl')

void scrollcam(float xoff, float zoff, float spd) {
                           ^

Identifier expected before 'float'.


Script error: data/chars/ryu/ryu.txt, line 564: Invalid declaration(expected comma, semicolon or initializer?) 'float' (in production 'decl')

void scrollcam(float xoff, float zoff, float spd) {
                                       ^



Script error: data/chars/ryu/ryu.txt, line 564: Invalid declaration(expected comma, semicolon or initializer?) ')' (in production 'decl')

void scrollcam(float xoff, float zoff, float spd) {
                                                ^


********** An Error Occurred **********
*            Shutting Down            *

Fatal Error in load_cached_model, file: data/chars/ryu/ryu.txt, line 2521, message: Error parsing function main of animation script in file '%s'!
Total Ram: 4294967295 Bytes
 Free Ram: 4294967295 Bytes
 Used Ram: 149630976 Bytes

Here the animation with the script:
Code:
anim fall44
	loop	0
	offset	82 177
	delay   20
        jumpframe 1 3 -0.3 0
	landframe  3
	bbox	    0 0 0 0
	sound   data/sounds/hit3.wav
   @script
void scrollcam(float xoff, float zoff, float spd) {
  if( openborvariant("in_level") ) {
    changelevelproperty("cameraxoffset", 7); //X offset for camera
    changelevelproperty("camerazoffset", 19); //Z offset for camera
    changelevelproperty("scrollspeed", 10); //Scrolling camera speed
  }
}
   @end_script 
	frame	data/chars/ryu/fall1.png
	frame	data/chars/ryu/fall2.png
	delay   999
        hitfx   data/sounds/indirect.wav
	attack  45 135 55 25 5 1 0 0 15
	frame	data/chars/ryu/fall3.png
	delay   1
        attack  0 0 0 0
	sound   data/sounds/fall1.wav
        frame   data/chars/ryu/fall4.png
        @cmd    anichange "ANI_FOLLOW15" 0
        frame   data/chars/ryu/fall4.png

 
It doesnt working because:
1) write the function in a file named animscript.c (for example)
2) in your entity.txt file write animationscript animscript.c
3) to call the function write between frames: @cmd scrollcam 7 19 10
 
White Dragon said:
It doesnt working because:
1) write the function in a file named animscript.c (for example)
2) in your entity.txt file write animationscript animscript.c
3) to call the function write between frames: @cmd scrollcam 7 19 10

Sorry my error.
Now I follow the steps, and works perfect.

One more question:
To return the camera to the normal position focus the player wath values are correct?

I try with 0 0 0  but not work.
Thanks!
 
In this case you have to improve that func:

Code:
void scrollcam(float xoff, float zoff, float spd, int reset) {
  if( openborvariant("in_level") ) {
    if ( reset > 0 ) {
        setlocalvar("stored_xoff",NULL());
        setlocalvar("stored_zoff",NULL());
	return;
    }
    if ( getlocalvar("stored_xoff") == NULL() ) {
        setlocalvar("stored_xoff",getlevelproperty("cameraxoffset"));
        setlocalvar("stored_zoff",getlevelproperty("camerazoffset"));
    }

    if ( spd == NULL() ) spd = 1;
    changelevelproperty("scrollspeed", spd); //Scrolling camera speed
    changelevelproperty("cameraxoffset", xoff); //X offset for camera
    changelevelproperty("camerazoffset", zoff); //Z offset for camera
  }

  return;
}

void restore_scrollcam(float spd) {
  if( openborvariant("in_level") ) {
    if ( spd == NULL() ) spd = 1;
    if ( getlocalvar("stored_xoff") != NULL() && getlocalvar("stored_zoff") != NULL() ) {
    	changelevelproperty("scrollspeed", spd); //Scrolling camera speed
    	changelevelproperty("cameraxoffset", getlocalvar("stored_xoff")); //X offset for camera
    	changelevelproperty("camerazoffset", getlocalvar("stored_zoff")); //Z offset for camera
    }
  }

  return;
}

use restore_scrollcam() func to restore prev cam.
you can reset saved values with reset flag how you see ^__^
 
Hello guys, how can i use this script to change te camera offset in the certain point of the level? Seems White Drangon did it in TMNT Shell Shocked Beach level.
So i have a large and wide stage and my camera starts with a offset llike -123, i need this offset and set some walls to prevent camera to show a no playable game area beneath the player character, but after player walk ahead in mte half of the stage at 2000 pixels i have a diagonal descend and and here a need to change the camera offset to not show the uncessary area above the player. Its exectaly like in White Drangon did it in TMNT Shell Shocked Beach level. I took a look at the data folder of his game, found the script in the level txt but i didnt undestand.... please help me guys...
 
My advice would be to not do such complex things and try to adapt your graphics so it works fine with default settings of the engine.
In other words dont try to make a game with things you dont know how to do.CAuse it might cause you to stop making the game completely.
IF you really want to do it, youd need separate entity co control the camera movement, to store its coords and lock it/unlock it with script commands.
 
@kdo: You should try changing camera offset manually with script at certain scroll poses. You do that with this script:
C:
spawn   delay
@script
void main()
{
    changelevelproperty("cameraxoffset", 100); //X offset for camera
    changelevelproperty("camerazoffset", 50); //Z offset for camera
}
@end_script
coords  160 190
at    2000

This script is run when delay entity is spawned at scrollpos 2000. You can declare this script on other entity spawn, so no need to get delay entity.
This script will set cameraoffset 100 50 at that scrollpos. 100 50 is just example, you can change these values to any value you need.

You can declare above script again in other scrollpos if you need to alter cameraoffset again.
 
Hello guys, thank you for help!! i appreciate.

@Bloodbane i have try like this:

spawn empty

@script
void main()
{
changelevelproperty("cameraxoffset", -123); //X offset for camera
changelevelproperty("camerazoffset", -60); //Z offset for camera
}
@end_script
coords 160 190
at 4000


It works, but when camera ofset changes the player character is thrown suddenly to right corner of the screen, the camerra offset works in the new correct position but the char has change.
 
Now its works, just made some adjustments and set the correct values in level file, like this:

anel data/bgs/lv1/1.png
frontpanel data/bgs/lv1/empty.png
background data/bgs/lv1/empty.png

music data/music/lv1.bor




Wall


bgspeed 3 1



order a
direction both
settime 0
notime 1

noreset 2

spawn1 180 20 160

noslow 1



cameratype 1

cameraoffset 0 -123 -123


scrollspeed 100




spawn1 31 80 0


spawn metroida

coords 200 0
at 0

spawn empty

@script
void main()
{
changelevelproperty("cameraxoffset", 2); //X offset for camera
changelevelproperty("camerazoffset", -40); //Z offset for camera
}
@end_script
coords -100 -100
at 4408
 
Great that you figured that out, problem with camera movement is that it wont push characters forward or characters will go offscreen , you have to take control over property subject_to_screen and i have invisible entity that has a script to push players forward when screen is moving and they touch the edge of the screen so they dont disappear off screen.
 
Back
Top Bottom