collision with a specific entity

Posted By: Denn15

collision with a specific entity - 01/07/13 15:45

ive managed to find out how to make something happen when any entity collides with an entity but how do i make only a specific entity react with another entity.
like for example i have a powerup that can only be collected by touching it with the player and not when you shoot it with another entity or enemy entities collide with it.
Posted By: rayp

Re: collision with a specific entity - 01/07/13 16:10

Code:
#define id skill100
#define powerup 1

..
if (event_type == EVENT_ENTITY){ // fex
   if (you) if (you.id == powerup) _do_something();
}
..


and in the other model say
Code:
..
 my.id = powerup;
 ..



greets
Posted By: Denn15

Re: collision with a specific entity - 01/08/13 18:12

ive tried it out with this script but nothing happens when they hit each other

Code:
#include <acknex.h>
#include <default.c>

#define id skill100
#define powerup 1

SOUND* sound = "gem.wav";
ENTITY* gem;
ENTITY* player_box;

function test()
{
	snd_play(sound,100,0);
}

action player_move()
{
	player_box = my;
	my.id = powerup;
	my.emask |= (ENABLE_IMPACT);
	while (1)
	{
		c_move(me, nullvector, vector((key_cuu-key_cud)*10*time_step, 0, (key_cur-key_cul)*10*time_step), GLIDE);
		wait (1);
	}
}

action gem_action()
{
	gem = my;
	my.emask |= (ENABLE_IMPACT);
	if (event_type == EVENT_IMPACT)
	{
		if (you) if (you.id== powerup) 
		{
			test();
		}
	}
}

function cam()
{
	while (1)
	{
		camera.x = - 300;
		camera.z =  450;
		camera.tilt = -30;
		wait (1);
	}
}

function main()
{
	level_load ("level.wmb");
	cam();
}

Posted By: rayp

Re: collision with a specific entity - 01/08/13 18:35

You should read about events.

Code:
..
 void _this_is_a_event(){
   if (event_type....
 }
 ..
 action bla...
 my.emask |= ENABLE_BLABLA
 my.event = _this_is_a_event; // note not ()

Posted By: Denn15

Re: collision with a specific entity - 01/09/13 14:46

sorry i didnt notice that i made that mistake. it works now laugh
Posted By: rayp

Re: collision with a specific entity - 01/09/13 14:55

No problem. We all make mistakes every day. Im glad it works now.
greets
Posted By: Denn15

Re: collision with a specific entity - 01/10/13 18:06

one last question though. isnt it possible to use the entitys name instead of the id thingy? thst way it would be easier
Posted By: sivan

Re: collision with a specific entity - 01/10/13 19:07

use str_for_entfile or str_for_entname if you have the collider entity to get its filename or name in wed respectively.
© 2024 lite-C Forums