Quake Effect? (SOLVED)

Fixer90

Member
In Cave Story's scripting, inputting a simple <QUA will make the entire screen shake somewhat violently until the end of the command. What kind of code could I use, that I could put in the form of a script command (or an object's create event) that would make a continuous earthquake-like effect?
 

obscene

Member
You can just randomize the view_xview, view_yview and view_angle assuming you are using views. Create an object that does that for a second and then sets it back to how it started.
 

Fixer90

Member
You can just randomize the view_xview, view_yview and view_angle assuming you are using views. Create an object that does that for a second and then sets it back to how it started.
Is there a variable that represents what the original view was?
 
Z

zendraw

Guest
0 is the default value for the angle, the x and y depend on how you move the view, thus you will have to find yourself.
 

Fixer90

Member
0 is the default value for the angle, the x and y depend on how you move the view, thus you will have to find yourself.
As @blacklemon said, just before you start the effect get the view coordinates and set them back when you're done.
So I've set up my quake object like this:
CREATE EVENT
Code:
intensity = 1;
destroy_quake = false;
current_xview = view_xview[view_current];
current_yview = view_yview[view_current];

alarm[0] = 6;
ALARM 0
Code:
view_xview[view_current] = choose(current_xview + intensity, current_yview - intensity);
view_yview[view_current] = choose(current_yview + intensity, current_yview - intensity);

alarm[0] = 6;
But it does nothing. Now, if the answer as to why it doesn't work is obvious, forgive me; I'm still learning views.
 

DukeSoft

Member
I usually have a script like so;

create;
Code:
screenshake  =0;
follow_obj = obj_player;
view_w = 1280; //Original values
view_h = 720; //Original values
step:

Code:
view_xview=follow_obj.x-view_wview/2;
view_yview=follow_obj.y-view_hview/2;

view_xview = view_xview-screenshake*3 + random(screenshake*6);
view_yview = view_yview-screenshake*3 + random(screenshake*6);
view_angle = -screenshake + random(screenshake*2);
view_wview = view_w - screenshake*2 + random(screenshake*4)
view_hview = view_h - screenshake*2 + random(screenshake*4)

screenshake -= 0.5*delta //If you don't have a delta variable, leave it out
if (screenshake < 0) {
    screenshake = 0;
}
Now on the event of an explosion, you just set screenshake to a value, e.g. 10, and you're done! :)

EDIT: You might need some tweaking in the script. Just written it from the top of my head and might be bug-ridden.
 

obscene

Member
A few things....

First, 1 is a small value, and 6 is not very often. So just at least for testing you might want to use some extreme values to make sure it's working. I'd put it in the step event, and I'd move the view like 10-20 pixels.

Secondly, I'd move it based on the starting position, not the current position, otherwise your view will "drift and jitter" instead of shake.

ie...
view_xview(0)=current_xview+random_range(-20,20);

Thirdly, if you have any other object somewhere setting the view, make sure it's off, or make sure you are setting your quake effect to run afterwards, for instance putting this in the end step event.
 

Fixer90

Member
A few things....

First, 1 is a small value, and 6 is not very often. So just at least for testing you might want to use some extreme values to make sure it's working. I'd put it in the step event, and I'd move the view like 10-20 pixels.

Secondly, I'd move it based on the starting position, not the current position, otherwise your view will "drift and jitter" instead of shake.

ie...
view_xview(0)=current_xview+random_range(-20,20);

Thirdly, if you have any other object somewhere setting the view, make sure it's off, or make sure you are setting your quake effect to run afterwards, for instance putting this in the end step event.
I changed the intensity to 16, and changed the alarm to go off/loop every 0.05 of a second (20 times per second).

Code:
intensity = 16;
destroy_quake = false;
current_xview = view_xview[view_current];
current_yview = view_yview[view_current];

scr_wait(0.05, 0);
Code:
view_xview[view_current] = current_xview + random_range(-intensity, intensity);
view_xview[view_current] = current_xview + random_range(-intensity, intensity);

scr_wait(0.05, 0);
(scr_wait is a script in which argument0 represents how much time in seconds the alarm will be, and argument1 is the alarm event it will go to)
 

CMAllen

Member
Another suggestion to enhance this effect might be to start out with a much larger intensity value, but have the intensity decrease over the lifetime of the quake event, giving it gradual ramp-out effect. You could also start with a smaller intensity value and create an intensity_shift variable that gets added to the intensity as the quake effect runs. Then, when intensity reaches its peak value (which can either be hardcoded into the quake effect itself or a variable you can pass in to control the quake effect), invert the sign of your intensity_shift, causing the intensity to decrease. Then the quake effect has both a ramp-in and ramp-out.

Note: the ramp-in, ramp-out speed in the above example take place at equal rates, but it's easy to make that adjustable, having either one operate at different rates.
 

Fixer90

Member
It works now, but when the player, the camera's target, appears, the quaking no longer works. I tried adding a code to the quake object that expands the hbor and vbor while the instance is there, but that didn't work.
 

obscene

Member
Thirdly, if you have any other object somewhere setting the view, make sure it's off, or make sure you are setting your quake effect to run afterwards, for instance putting this in the end step event.
 

Fixer90

Member
Ah, yes. I had forgotten about that detail. Well, I was able to fix it using this code:
Code:
view_object = undefined;
And of course re-targeting the correct instance upon the destruction of the quake object.

Thanks for the help guys!
 

DukeSoft

Member
Ah, yes. I had forgotten about that detail. Well, I was able to fix it using this code:
Code:
view_object = undefined;
And of course re-targeting the correct instance upon the destruction of the quake object.

Thanks for the help guys!
Why not keep track of it and adding the quake effect? Now if the quake effect takes a second the play can walk to the side of the view for 1 second. I actually wrote some code for you that does that
 
Top