Inside3D!
     

Activate an entity(MOVETYPE_BOUNCE) via impulse?

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
Moi



Joined: 20 Jul 2010
Posts: 9

PostPosted: Wed Jul 21, 2010 11:58 am    Post subject: Activate an entity(MOVETYPE_BOUNCE) via impulse? Reply with quote

hi everyone.
i'm looking for a simple solution to let a map object fall from the ceiling when a keyboard key is pressed. My first idea was to create a func_train which checks if a global variable is set to 0 or 1. if the variable is set to 1 (via an impulse) the func_train starts following its waypoints.
However before completing this idea I thought of a better one. I was planning to create a solid map entity and reset its self.movetype once a special key is pressed. that's how i tried it:

Code:

//basically just a little modified func_train
void() func_impulse_train =
{

self.solid = SOLID_BSP;

//start as 'pushable' entity since trainactivated is initialized with 0
   if(self.trainactivated==0){self.movetype = MOVETYPE_PUSH;}

//once impulse 22 is activated, let the entity bounce down
   else if(self.trainactivated==1){self.movetype = MOVETYPE_BOUNCE;}
   

   self.blocked = train_blocked;
   self.use = train_use;
   self.classname = "train";

   setmodel (self, self.model);
   setsize (self, self.mins , self.maxs);
   setorigin (self, self.origin);

// start trains on the second frame, to make sure their targets have had
// a chance to spawn
   self.nextthink = self.ltime + 0.1;

//restart the function to recheck the state of trainactivated
   self.think = func_impulse_train;
   

};


For some reason it won't work. I'd be glad to hear from you guys Very Happy
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Wed Jul 21, 2010 12:16 pm    Post subject: Reply with quote

nextthink works differently depending on movetype.
for movetype_push its dependant upon self.ltime.
for anything else, its dependant upon time.

movetype_bounce will clip the object against others as though its a bounding box.
considering you're making a bsp object, your origin starts at '0 0 0'.
so your movetype_bounce will never get anywhere.

also, please don't use your spawn function as a think function. its not pretty.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Moi



Joined: 20 Jul 2010
Posts: 9

PostPosted: Wed Jul 21, 2010 12:30 pm    Post subject: Reply with quote

Spike wrote:
nextthink works differently depending on movetype.
for movetype_push its dependant upon self.ltime.
for anything else, its dependant upon time.

Thanks for the quick reply. I should have added that I also included the gyro and sagdoll libraries, so I have no idea if they have an influence on the code.

Quote:

movetype_bounce will clip the object against others as though its a bounding box.

That's the effect I'm looking for Very Happy

Quote:

considering you're making a bsp object, your origin starts at '0 0 0'.
so your movetype_bounce will never get anywhere.

I'm not sure if I'm understanding you correctly. The object I was talking about was created in worldcraft using the tietoEntity feature. So it's definitely visible on the map and also works with my code when initialized with MOVE_BOUNCE(when I reverse the if case in 'my' code).

Quote:

also, please don't use your spawn function as a think function. its not pretty.

Hehe by now you should've guessed that you are talking to a QC n00b. Thanks for the advice Very Happy
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Wed Jul 21, 2010 2:08 pm    Post subject: Reply with quote

Moi wrote:

I'm not sure if I'm understanding you correctly. The object I was talking about was created in worldcraft using the tietoEntity feature. So it's definitely visible on the map and also works with my code when initialized with MOVE_BOUNCE(when I reverse the if case in 'my' code).

geometry created and present inside the bsp? then its a bsp object, and its origin will be '0 0 0', even if its mins/max are in one tiny non-central part of the map.
And because its origin is '0 0 0', its not going to collide against the world in the place that you actually expected.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Moi



Joined: 20 Jul 2010
Posts: 9

PostPosted: Wed Jul 21, 2010 2:48 pm    Post subject: Reply with quote

Spike wrote:

geometry created and present inside the bsp? then its a bsp object, and its origin will be '0 0 0', even if its mins/max are in one tiny non-central part of the map.
And because its origin is '0 0 0', its not going to collide against the world in the place that you actually expected.


Well, funny thing is that it does fall and collide against the world when it's initialized as self.movetype = MOVETYPE_BOUNCE. But again calling "impulse 22" while it's falling won't turn it to MOVETYPE_PUSH as the (reversed) code checking the variable suggests.Sorry for my vague description of "it won't work" in my first post btw.

Anyway are you suggesting finding the position of func_impulse_train in my map after "impulse 22" was called and then reset the entity's movetype? Or even better: How would an experienced QC coder solve the problem Very Happy
Back to top
View user's profile Send private message
frag.machine



Joined: 25 Nov 2006
Posts: 728

PostPosted: Wed Jul 21, 2010 3:04 pm    Post subject: Reply with quote

One way would be to create a BSP type entity that behaves like a func_wall, adding a use() function that, when triggered, removes the original entity and spawns a new one with MOVETYPE_BOUNCE in the same place. And make your impulse code to find the entity and fire its use() function instead setting the global var.
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/
Back to top
View user's profile Send private message Visit poster's website
Moi



Joined: 20 Jul 2010
Posts: 9

PostPosted: Thu Jul 22, 2010 1:22 pm    Post subject: Reply with quote

thanks frag.machine. I've tried it the way you described but failed to implement it due to my limited qc knowledge. but i came up with a similar way, which is kinda a mix of my original idea and your idea:

Code:

//misc.qc
void() func_dropped_weight =
{
   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_PUSH;

   self.blocked = weight_blocked;

   setmodel (self, self.model);
   setsize (self, self.mins , self.maxs);
   setorigin (self, self.origin);
   

};



Code:

//ImpulseCommands

if (self.impulse == 22)
   {
   local entity e;
   e=find(world,classname,"func_dropped_weight" );
   e.movetype = MOVETYPE_BOUNCE;
   }



Am I missing anything QC related in that code that might cause issues in future?
Back to top
View user's profile Send private message
frag.machine



Joined: 25 Nov 2006
Posts: 728

PostPosted: Thu Jul 22, 2010 3:59 pm    Post subject: Reply with quote

Moi wrote:
thanks frag.machine. I've tried it the way you described but failed to implement it due to my limited qc knowledge. but i came up with a similar way, which is kinda a mix of my original idea and your idea:

Code:

//misc.qc
void() func_dropped_weight =
{
   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_PUSH;

   self.blocked = weight_blocked;

   setmodel (self, self.model);
   setsize (self, self.mins , self.maxs);
   setorigin (self, self.origin);
   

};



Code:

//ImpulseCommands

if (self.impulse == 22)
   {
   local entity e;
   e=find(world,classname,"func_dropped_weight" );
   e.movetype = MOVETYPE_BOUNCE;
   }



Am I missing anything QC related in that code that might cause issues in future?


In a quick look I'd say you should check if the entity exists before changing .movetype:
Code:

//ImpulseCommands

if (self.impulse == 22)
   {
   local entity e;
   e=find(world,classname,"func_dropped_weight" );
        if (e != world) {
          e.movetype = MOVETYPE_BOUNCE;
        }
   }


_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/
Back to top
View user's profile Send private message Visit poster's website
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Thu Jul 22, 2010 4:15 pm    Post subject: Reply with quote

MOVETYPE_PUSH has a distinct preference for SOLID_BSP, although DP doesn't really care.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Moi



Joined: 20 Jul 2010
Posts: 9

PostPosted: Thu Jul 22, 2010 4:22 pm    Post subject: Reply with quote

frag.machine wrote:


In a quick look I'd say you should check if the entity exists before changing .movetype:
Code:

//ImpulseCommands

if (self.impulse == 22)
   {
   local entity e;
   e=find(world,classname,"func_dropped_weight" );
        if (e != world) {
          e.movetype = MOVETYPE_BOUNCE;
        }
   }



Thanks. I guess it also would be a good idea to remove e if find() isn't successful, wouldn't it?
Btw does find return some king of a null pointer if the entity is not found?



Quote:
MOVETYPE_PUSH has a distinct preference for SOLID_BSP, although DP doesn't really care.

yeah I had to use SOLID_SLIDEBOX to stop the crashing in makaqu.
Back to top
View user's profile Send private message
frag.machine



Joined: 25 Nov 2006
Posts: 728

PostPosted: Thu Jul 22, 2010 7:01 pm    Post subject: Reply with quote

Moi wrote:
frag.machine wrote:


In a quick look I'd say you should check if the entity exists before changing .movetype:
Code:

//ImpulseCommands

if (self.impulse == 22)
   {
   local entity e;
   e=find(world,classname,"func_dropped_weight" );
        if (e != world) {
          e.movetype = MOVETYPE_BOUNCE;
        }
   }



Thanks. I guess it also would be a good idea to remove e if find() isn't successful, wouldn't it?
Btw does find return some king of a null pointer if the entity is not found?


There's no such thing as "null" in QuakeC; if find() fails, a reference to entity 0 (== world) is returned. It's safe to just ignore it.
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group