if entity touches another entity

Discuss programming in the QuakeC language.
Post Reply
ThePlasticBling
Posts: 51
Joined: Fri Jun 04, 2010 10:18 pm

if entity touches another entity

Post by ThePlasticBling »

how would i do this? example: if entity 1 touches entity 2 then do something
daemonicky
Posts: 185
Joined: Wed Apr 13, 2011 1:34 pm

Re: if entity touches another entity

Post 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;
...
daemonicky
Posts: 185
Joined: Wed Apr 13, 2011 1:34 pm

Post 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 .
ThePlasticBling
Posts: 51
Joined: Fri Jun 04, 2010 10:18 pm

Post by ThePlasticBling »

it says that the second entity is an unknown value
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post 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.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
ThePlasticBling
Posts: 51
Joined: Fri Jun 04, 2010 10:18 pm

Post 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.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post 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.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Post Reply