Gamestudio Links
Zorro Links
Newest Posts
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 08/21/19 14:59
Alarm whenever logged out from Broker
by chsmac85. 08/21/19 14:36
What are you working on?
by 3run. 08/21/19 13:28
file_write var array ?
by laz. 08/20/19 17:18
Updating Assets<Brokername
>.csv

by Sabre. 08/20/19 15:40
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
8 registered members (RealSerious3D, 3run, AndrewAMD, Southqvist, kankan, 3 invisible), 640 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
GorgonzolaBYTE, Southqvist, tawin, Raedwulf, Sabre
18270 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
FPS Damage effect #472315
04/19/18 18:51
04/19/18 18:51
Joined: May 2009
Posts: 5,110
Caucasus
3run Online OP
Senior Expert
3run  Online OP
Senior Expert

Joined: May 2009
Posts: 5,110
Caucasus
Hi!

Another simple camera effect, this time it goes for damage.
Code:
#include <acknex.h>
#include <default.c>

#define PRAGMA_POINTER

void player_damage_effect(ANGLE *damage, ANGLE *lerp, VECTOR *from, VECTOR *to){
	
	var damage_pan = 0.25, damage_tilt = 2.5, damage_roll = 2.5;
	
	ANGLE hit_angle;
	vec_to_angle(&hit_angle, vec_diff(NULL, &from->x, &to->x));
	var target_ang = ang(hit_angle.pan - camera->pan);
	
	// front hit
	if(abs(target_ang) < 45){
		
		// up/down
		if(random(1) > 0.5){ damage->tilt += (damage_tilt + random(damage_tilt)); }
		else{ damage->tilt -= (damage_tilt + random(damage_tilt)); }
		
		// left/right
		if(random(1) > 0.5){ damage->pan += (damage_pan + random(damage_pan)); }
		else{ damage->pan -= (damage_pan + random(damage_pan)); }
		
	}
	else{
		
		if(abs(target_ang) < 135){
			
			// left-right
			if(target_ang > 0){
				
				// towards the left
				if(random(1) < 0.75){ damage->roll += (damage_roll + random(damage_roll)); }
				else{ damage->roll -= (damage_roll + random(damage_roll)) / 2; }
				
			} 
			else{
				
				// towards the right
				if(random(1) < 0.75){ damage->roll -= (damage_roll + random(damage_roll)); }
				else{ damage->roll += (damage_roll + random(damage_roll)) / 2; }
				
			}
			
		} 
		else{
			
			// down (hit from backwards)
			damage->tilt -= (damage_tilt + random(damage_tilt));
			
			// left/right
			if(random(1) > 0.5){ damage->pan += (damage_pan + random(damage_pan)); }
			else{ damage->pan -= (damage_pan + random(damage_pan)); }
			
		}
		
	}
	
}

void main(){
	
	warn_level = 6;

	fps_max = 60;
	fps_min = 30;
	time_smooth = 0.9;
	
	freeze_mode = 1;
	level_load("");
	wait(3);
	freeze_mode = 0;
	
	shadow_stencil = 2;
	sun_light = 1;
	
	level_ent = ent_create(CUBE_MDL, vector(0, 0, -16), NULL);
	vec_set(&level_ent->scale_x, vector(20, 20, 0.1));
	set(level_ent, PASSABLE | LIGHT | UNLIT | SHADOW);
	level_ent->ambient = 0;
	vec_set(&level_ent->blue, COLOR_GREY);
	
	ENTITY *enemy_ent = ent_create(CUBE_MDL, vector(128, 0, 0), NULL);
	set(enemy_ent, PASSABLE | LIGHT | UNLIT | SHADOW);
	enemy_ent->ambient = 0;
	vec_set(&enemy_ent->blue, COLOR_RED);
	
	ENTITY *enemy2_ent = ent_create(CUBE_MDL, vector(-128, 0, 0), NULL);
	set(enemy2_ent, PASSABLE | LIGHT | UNLIT | SHADOW);
	enemy2_ent->ambient = 0;
	vec_set(&enemy2_ent->blue, COLOR_BLUE);
	
	ENTITY *player_ent = ent_create(CUBE_MDL, nullvector, NULL);
	set(player_ent, PASSABLE | LIGHT | UNLIT | SHADOW);
	player_ent->ambient = 0;
	vec_set(&enemy_ent->blue, COLOR_GREEN);
	
	ANGLE cam_angle;
	vec_fill(&cam_angle, 0);
	
	ANGLE damage_angle, damage_lerp;
	vec_fill(&damage_angle, 0);
	vec_fill(&damage_lerp, 0);
	var hit_once = 0, hit_counter = 0;
	
	while(player_ent){
		
		cam_angle.pan = cycle(cam_angle.pan - mickey.x / 6.5, 0, 360);
		cam_angle.tilt = clamp(cam_angle.tilt - mickey.y / 6.5, -90, 90);
		cam_angle.roll = 0;
		
		player_ent->skill1 = 5 * (key_w - key_s) * time_step;
		player_ent->skill2 = 5 * (key_a - key_d) * time_step;
		player_ent->skill3 = 0;		
		vec_rotate(&player_ent->skill1, vector(camera->pan, 0, 0));		
		c_move(player_ent, nullvector, &player_ent->skill1, IGNORE_PASSABLE | GLIDE);
		
		// hit effect
		if(enemy_ent && mouse_left && hit_once == 0){
			
			player_damage_effect(&damage_angle, &damage_lerp, &enemy_ent->x, &camera->x);
			
			hit_once = 1;
			
		}
		
		if(hit_once == 1){
			
			hit_counter += time_frame / 16;
			if(hit_counter >= 0.1){
				
				hit_counter -= 0.1;
				hit_once = 0;
				
			}
			
		}
		
		vec_set(&camera->x, &player_ent->x);
		
		// accelerate
		damage_lerp.pan -= ang(damage_lerp.pan - damage_angle.pan) * 0.25 * time_step;
		damage_lerp.tilt -= ang(damage_lerp.tilt - damage_angle.tilt) * time_step;
		damage_lerp.roll -= ang(damage_lerp.roll - damage_angle.roll) * time_step;
		
		// reset force
		damage_angle.pan -= ang(damage_angle.pan - 0) * time_step;
		damage_angle.pan = clamp(damage_angle.pan, -2.5, 2.5);
		damage_angle.tilt -= ang(damage_angle.tilt - 0) * 0.5 * time_step;
		damage_angle.tilt = clamp(damage_angle.tilt, -5, 5);
		damage_angle.roll -= ang(damage_angle.roll - 0) * 0.5 * time_step;
		damage_angle.roll = clamp(damage_angle.roll, -5, 5);
		
		camera->pan = cam_angle.pan + damage_angle.pan;
		camera->tilt = cam_angle.tilt + damage_lerp.tilt;
		camera->roll = cam_angle.roll + damage_lerp.roll;
		
		if(key_e){ fps_max = 20; }
		else{ fps_max = 60; }
		DEBUG_VAR(fps_max, 10);
		
		wait(1);
		
	}
	
}

Thx to txesmi, for his 'relative' angle laugh Part of it was used here.

Best regards!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Re: FPS Damage effect [Re: 3run] #472329
04/21/18 02:19
04/21/18 02:19
Joined: Mar 2018
Posts: 37
Blobfist Offline
Newbie
Blobfist  Offline
Newbie

Joined: Mar 2018
Posts: 37
Cool!
I will try this out tongue


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