Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, 7th_zorro, ozgur, Quad), 841 guests, and 0 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
Page 3 of 3 1 2 3
Re: c_scan and a big world [Re: Reconnoiter] #445212
08/30/14 20:14
08/30/14 20:14
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline
Expert
alibaba  Offline
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
So is this solved?
If not, iīll create an example code for you.


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: c_scan and a big world [Re: alibaba] #445213
08/30/14 21:01
08/30/14 21:01
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Originally Posted By: alibaba
So is this solved?
If not, iīll create an example code for you.
, no I cant seem to get the scan relative of the missile's position and angle. If you have examples than great laugh .

Re: c_scan and a big world [Re: Reconnoiter] #445216
08/30/14 21:57
08/30/14 21:57
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline
Expert
alibaba  Offline
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
Here is a working example, i tried to comment and explain as good as i could and tried my best to show the problem.
Just copy the code into an empty .c file and run it. No models whatsoever needed:
Code:
#include <acknex.h>
#include <default.c>

void Barrel()
{
	//Just a placeholder
	set(my,FLAG8);
	my.skill1=100;
	while(my.skill1>0)
	{
		wait(1);
	}
	safe_remove(me);
}

void create_barrel()
{
	VECTOR to;
	vec_set(to,mouse_dir3d);
	vec_scale(to,1000); // set a range
	vec_add(to,mouse_pos3d);
	c_trace(mouse_pos3d,to,0);
	if(trace_hit)
	//This wonīt work, because entity is too high!
	//ent_create(CUBE_MDL,vector(target.x,target.y,target.z+20),Barrel);
	//This will work
	ent_create(CUBE_MDL,vector(target.x,target.y,target.z+10),Barrel);
}
var RocketRange=100;
var RocketScanHeight=10;
 
void HitEvent()
{
	//If hit something
	if(event_type==EVENT_IMPACT||event_type==EVENT_ENTITY)
	{
		//The Problem is here. If you comment out this line, then youīll see that the scan-circle 
		//is rotated into the ground, so you got like no chance to scan anything. To really have the
		//full scan-range, you need to reset itīs rotation
		vec_set(my.pan,nullvector);
		//Scan around
		c_scan(my.x,my.pan,vector(360,0,RocketRange),IGNORE_PASSABLE|IGNORE_ME);
		//And tell the rocket you hit something
		my.skill2=1; 
		//You can remove this line, itīs just to show you the range of the rockets
	//	wait(-1);
		//Now we can remove everything
		my.skill2=2;
	}
	//If scanned something
	if(event_type==EVENT_DETECT)
	{
		//And you are marked as enemy
		if(is(you,FLAG8))
		{
			//And you are withing the height between -10 and 10
			VECTOR temp;
			vec_set(temp.x,you.x);
			vec_to_ent(temp.x,my);
			if(abs(temp.z)<RocketScanHeight)
			{
				//set you health to 0
				you.skill1=0;
			}
		}
	}
}
void shoot_rocket(VECTOR* targetVec)
{
	//We have to save the parameter in order not to lose it
	VECTOR RocketTarget;
	vec_set(RocketTarget,targetVec);
	//No create the rocket
	ENTITY* RocketEnt=ent_create(CUBE_MDL,vector(player.x,player.y,player.z+50),NULL);
	//scale it down
	vec_scale(RocketEnt.scale_x,0.2);
	//Make it react to touches and detected entites
	RocketEnt.emask|=ENABLE_ENTITY|ENABLE_IMPACT|ENABLE_DETECT;
	RocketEnt.event=HitEvent;
	//The variable for acceleration
	var RocketSpeed=0;
	
	//The range indicator
	ENTITY* range=ent_create(SPHERE_MDL,my.x,NULL);
	//Scale it to the range of the rocket
	vec_scale(range.scale_x,RocketRange/8);
	range.scale_z=RocketScanHeight/8;
	//make it transparent
	set(range,TRANSLUCENT|PASSABLE);
	range.alpha=50;
	
	//Fly as long as we hit nothing
	while(RocketEnt.skill2==0)
	{
		//Target our destination
		vec_to_angle(RocketEnt.pan,vec_diff(NULL,RocketTarget.x,RocketEnt.x));
		//Accelerate to get the "rocket effect"
		accelerate(RocketSpeed,0.5,0);
		c_move(RocketEnt,vector(RocketSpeed,0,0),nullvector,IGNORE_PASSABLE|USE_POLYGON);
		
		//set the range indicator to rockets position and orientation
		vec_set(range.x,RocketEnt.x);
		vec_set(range.pan,RocketEnt.pan);
		
		//You can uncomment this line to really see how the rotation makes a difference
		//RocketEnt.roll+=5*time_step;
		wait(1);
	}
	//When we hit something, wait until we can remove it
	while(RocketEnt.skill2==1)wait(1);
	//Reset the event and remove everything
	RocketEnt.event=NULL;
	safe_remove(range);
	safe_remove(RocketEnt);
}

void playerEnt()
{
	player=me;
	VECTOR to;
	var RocketTime=0;
	while(1)
	{
		draw_text("Shoot with [mouse_left]\ncreate barrels with [mouse_right]\nmove with WASD",0,0,COLOR_WHITE);
		//Mark our target 
		vec_set(to,mouse_dir3d);
		vec_scale(to,1000); // set a range
		vec_add(to,mouse_pos3d);
		c_trace(mouse_pos3d,to,0);
		if(trace_hit)
		draw_point3d(vector(target.x,target.y,target.z+10),COLOR_RED,100,10);
		
		//Shoot 2 rockets every second
		if(mouse_left&&RocketTime>0.5)
		{
			shoot_rocket(target.x);
			RocketTime=0;
		}
		RocketTime+=time_step/16;
		//Rotate to the mouse pointer
		vec_to_angle(my.pan,vec_diff(NULL,target.x,my.x));
		c_move(my,vector(3*(key_w-key_s),3*(key_a-key_d),0),vector(0,0,-1),GLIDE);
		wait(1);
	}
	
}

void main()
{
	fps_max=60;
	level_load("");
	//Let the mouse have influence
	mouse_mode=4;
	//Create the playground
	you=ent_create(CUBE_MDL,nullvector,NULL);
	you.scale_x=50;
	you.scale_y=50;
	set(you,POLYGON);
	//set camera position
	vec_set(camera.x,vector(0,0,500));
	camera.tilt=-90;
	//Create the player
	ent_create(CUBE_MDL,vector(0,0,10),playerEnt);
	on_mouse_right=create_barrel;
}



Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: c_scan and a big world [Re: alibaba] #445233
08/31/14 19:42
08/31/14 19:42
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
First I want to thank you all for your angelic patience. I know it is not always easy to help me with my code and sometimes it's a long journey grin.

I did alot of testing today with the various solutions offered:

@Wjbender, while I really like the idea of your method, the results are funny when using a disk shape as an explosion. When firing the horizontal disk, enemies walking towards the player will move over it (even while I do 1 ignore_group before the enemy's c_move and 1 before their c_trace). Maybe my problem is not using the right engine function to trigger event_impact (I have tried c_rotate and c_move). But next to that it seems to work good enough. I have c&p the code below.

@alibaba, your sample that not seem to work always eek. If I comment "vec_set(my.pan,nullvector);" (found in the HitEvent function) and e.g. set "RocketEnt.roll = 90;" in the shoot_rocket action, it works better but still not always.


My version of Wjbender's-idea-like explosion (created at the end of the player missile):

Code:
action explosion_playermissile()
{
 VECTOR scan_sector;	
 my.group = 1; //for player projectiles	
 set(my,FLAG2);	
 my.WEAPONSELECTED = you.WEAPONSELECTED;
 my.DAMAGE = you.DAMAGE;
 my.AREAOFEFFECT = you.AREAOFEFFECT;
 vec_set(my.pan,you.pan);
 
 vec_set(scan_sector, vector(my.AREAOFEFFECT, my.AREAOFEFFECT, my.AREAOFEFFECT));		
 if (my.WEAPONSELECTED == 5) scan_sector.z = 30;

 my.scale_x = scan_sector.x /45;
 my.scale_y = scan_sector.y /45;
 my.scale_z = scan_sector.z /45;
 wait(1);
 c_setminmax(me);
 
 var angle;
 for (angle = 0; angle < 360; angle += 30) 
 {
 ang_rotate(my.pan,vector(angle, 0, 0));
 // vec_add(my.pan, vector(-5, -5, -5));	
 // c_rotate(my, vector(5,5,5), IGNORE_FLAG2 | IGNORE_PASSABLE | IGNORE_WORLD);
 vec_add(my.x, vector(-5, -5, -5));
 c_move(my, nullvector, vector(5,5,5), IGNORE_FLAG2 | IGNORE_PASSABLE | IGNORE_WORLD);
 wait(1);
 }	
 ent_remove(me);
 	
}


Re: c_scan and a big world [Re: Reconnoiter] #445242
09/01/14 11:45
09/01/14 11:45
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline
Expert
alibaba  Offline
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
I donīt know why you removed the line.
The code works as it should, maybe you place the barrels on each other.


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: c_scan and a big world [Re: alibaba] #445243
09/01/14 12:56
09/01/14 12:56
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
I have tested the code as given by alibaba it does work , however it does only work when the rocket reaches the destination target , it does not account
for impacts in route and maby thats what the op
finds as a problem during testing ?

secondly , the rockets impact way before the target area
(possibly not that important for now)

if thats fixed maby it would work ..

Code:
void Barrel()
{
	//Just a placeholder
	set(my,FLAG8);
	my.skill1=100;
	while(my.skill1>0)
	{
		VECTOR pos;
		vec_set(pos,my.x);
		vec_to_screen(pos,camera);
		draw_text(str_printf(NULL,"%i",(long)my.z),pos.x,pos.y,COLOR_WHITE);
		wait(1);
	}
	safe_remove(me);
}



and yes you have to keep an eye on the height in alibab's example,i have include a text draw call in this function so
if you test you should see that any barrels too high would not
be detected , upon creation of those barrels it seems the
height is around 17 or 18..

Last edited by Wjbender; 09/01/14 14:03.

Compulsive compiler
Re: c_scan and a big world [Re: Wjbender] #445253
09/01/14 17:16
09/01/14 17:16
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
ok thanks guys! This has become a very informative thread concerning explosion damage with many different possible solutions. I will see if I can edit this thread's name so more people searching on explosions will find it.

-edit, can't, maybe a moderator can change it to e.g. [ many explosion damage solutions ] or such for others?

Last edited by Reconnoiter; 09/01/14 17:20.
Page 3 of 3 1 2 3

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