Forum

if entity touches another entity

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

if entity touches another entity

Postby ThePlasticBling » Fri May 06, 2011 10:05 pm

how would i do this? example: if entity 1 touches entity 2 then do something
ThePlasticBling
 
Posts: 51
Joined: Fri Jun 04, 2010 10:18 pm

Re: if entity touches another entity

Postby daemonicky » Fri May 06, 2011 10:29 pm

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;

...
User avatar
daemonicky
 
Posts: 185
Joined: Wed Apr 13, 2011 1:34 pm

Postby daemonicky » Fri May 06, 2011 10:35 pm

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

Postby ThePlasticBling » Fri May 06, 2011 11:23 pm

it says that the second entity is an unknown value
ThePlasticBling
 
Posts: 51
Joined: Fri Jun 04, 2010 10:18 pm

Postby frag.machine » Sat May 07, 2011 12:21 am

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)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby ThePlasticBling » Sat May 07, 2011 5:44 pm

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

Postby frag.machine » Sun May 08, 2011 10:34 pm

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)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest