Page 1 of 1

if entity touches another entity

Posted: Fri May 06, 2011 10:05 pm
by ThePlasticBling
how would i do this? example: if entity 1 touches entity 2 then do something

Re: if entity touches another entity

Posted: Fri May 06, 2011 10:29 pm
by daemonicky
ThePlasticBling wrote:how would i do this? example: if entity 1 touches entity 2 then do something
Quake C is event driven, engine simulates entities, if they collide, then he lets you to handle what to do. After you are done, he continues checking other collisions a and calling their handlers.

Handler for collision is "touch" function.
First, you create handler :

Code: Select all

void() ZombieGrenadeTouch =
{
// when two thing collide their collisions handlers are called
// because in collision there are always 2 entities
// then one entity is in variable "self" and other is in variable "other"

	if (other.classname == "entity 2")
	{
		T_Damage (other, self, self.owner, 10 );
	}
};

and second, You assing it to touch function like this :

...

Code: Select all

self.touch = ZombieGrenadeTouch;
...

Posted: Fri May 06, 2011 10:35 pm
by daemonicky
You also have to set movetype and solid. But it is too late to answer, because I am sleepy, and too early to know it well because I have started coding QC recently... :)

Basically search for "touch" in Quake's Quake C source code.
There are some code snippets and tutorials all over the inside3d , use google to search the site http://www.google.cz/search?q=site%3Ain ... search+for .

Posted: Fri May 06, 2011 11:23 pm
by ThePlasticBling
it says that the second entity is an unknown value

Posted: Sat May 07, 2011 12:21 am
by frag.machine
As daemonick said, when the engine detects that self (the currently active entity) is touched, it fires the .touch() function, setting other as the touching entity. For example, let's say you fire a rocket against a zombie; Quake eventually will assign self = your rocket and other = zombie, and run the rocket.touch() function, that makes it explode and destroy other by calling T_Damage ().

EDIT: spelling.

Posted: Sat May 07, 2011 5:44 pm
by ThePlasticBling
ok, i got that done. but heres what im trying to do: i want a rocket to be entity 1, and a wall to be entity 2. so when the rocket hits the wall, something happens. but in worldcraft, when i tie a wall to entity 2 (the entity that makes rocket dissapear when rocket collides with it) and run the game, the wall doesn't show up in the game.

Posted: Sun May 08, 2011 10:34 pm
by frag.machine
Use a func_button as wall, set health = 120 (the amount of damage applied by a rocket direct hit) and wait = -1 (so the button wont retrigger after some time). Also, adjust the .lip value so the button doesn't move when activated. This should achieve what you want.