View previous topic :: View next topic |
Author |
Message |
CocoT

Joined: 14 Dec 2004 Posts: 599 Location: Belly-Gum
|
Posted: Tue Jun 12, 2007 11:35 am Post subject: Little problem with a touch function |
|
|
Hi there
Okay, so I'm playing around with a little mini-mod and I have a little problem with a touch function. Basically, I'm using a yellow platform (in the form of a model) which turns red when you step on it, and (I would hope) stays red (and solid) when you stand on it, but then becomes transparent (and non-solid) when you stop touching it (in other words, when you step on another platform).
For some reason, I can't get the platform to remain solid as long as the player is standing on it.
This is the code:
.float touched;
.float touchytime;
.float alpha;
void() platform_touch =
{
if (self.touched == 0)
{
if (other.health > 1)
{
bprint("first touch");
self.skin = 1;
self.touched = 1;
sound(other, CHAN_ITEM, "items/armor1.wav", 1, ATTN_NORM);
}
}
if (self.touched == 1)
{
if (other.health > 1)
{
self.touchytime = time + 5;
bprint("constant touch");
}
}
};
void() platformthink =
{
self.touch = platform_touch;
if (self.touched == 0) self.touchytime = time + 1;
if (self.touched == 1 && (self.touchytime + 5) < time)
{
self.alpha = 0.4;
self.solid = SOLID_NOT;
}
self.think = platformthink;
self.nextthink = time + 1;
};
void() item_armor1 =
{
self.touch = platform_touch;
precache_model ("progs/armor.mdl");
setmodel (self, "progs/armor.mdl");
self.skin = 0;
setsize (self, '-64 -64 0', '64 64 20');
self.solid = SOLID_BBOX;
self.movetype = MOVETYPE_FLY;
self.think = platformthink;
self.nextthink = time + 1;
self.touchytime = time + 1;
};
I'm using the armor as the platform, as you can see. I know I could just make a new entity but, well, it does not make any difference since the mini-mod won't be using armors.
The weird thing is that I also never get my bprint messages, even though I do hear the sound when I step on a new platform and it does turn red (skin = 1). I have the feeling that there is something really simple that I'm missing, but I don't know what it is... Do you have suggestions?
Oh, and, when I continuously jump on the platform, it looks like the turning into non-solid takes longer...  _________________ http://www.planetcocot.net/ |
|
Back to top |
|
 |
FrikaC Site Admin

Joined: 08 Oct 2004 Posts: 947
|
Posted: Tue Jun 12, 2007 12:13 pm Post subject: |
|
|
First off, the bprints are probably working but you're just not seeing them because you didn't put new lines (\n) at the end of the bprint statements, so they're getting bunched up on the console.
Secondly, .touch only occurs the first time the entities impact, I don't think it retriggers when you stand on something, unless you set force_retouch. My only suggestion here might be to instead check if the player is on top of the platform every think rather than use .touch to renew the timer.
Also, SOLID_BBOX will cause the player to slide around uncontrollably when atop it. If you set the FL_ONGROUND flag, you can overcome this. |
|
Back to top |
|
 |
Spike
Joined: 05 Nov 2004 Posts: 944 Location: UK
|
Posted: Tue Jun 12, 2007 1:16 pm Post subject: |
|
|
the way I'd do it is to get the touch function to trigger thinks.
the think function would periodically check the groundentity field of the players. When it can no longer find the platform in the player's groundentity fields, the platform is removed.
This does require that the ground is SOLID_BSP, however.
But then I'm weird. _________________ What's a signature? |
|
Back to top |
|
 |
CocoT

Joined: 14 Dec 2004 Posts: 599 Location: Belly-Gum
|
Posted: Tue Jun 12, 2007 1:21 pm Post subject: |
|
|
Thanks for the answers, guys! I'm a little lost, but I'll try...
This is what I tried so far... It's based on the crouchcheck routine of the crouching tutorial, but I'm probably doing something wrong, because it does not work.
Oh, and the player does not slide when he's on top of that platform. Could it mean something?
float (entity targ) checkabove =
{
makevectors (self.v_angle);
tracebox (self.origin, '-64 -64 -24', '64 64 32', self.origin + '0 0 10', FALSE, self);
// vector VEC_HULL_MIN = '-64 -64 -24';
// vector VEC_HULL_MAX = '64 64 32';
if (trace_fraction == 1) //hits nothing go ahead
return TRUE;
else return FALSE;
};
void() platformthink =
{
self.touch = platform_touch;
// if (self.touched == 0) self.touchytime = time + 1;
if (self.touched == 2)
{
self.alpha = 0.4;
self.solid = SOLID_NOT;
}
if (self.touched == 1)
{
if (checkabove(self)) self.touched = 2;
else self.touched = 1;
}
self.think = platformthink;
self.nextthink = time + 1;
};
Sorry for the pretty aweful code, I'm sure...  _________________ http://www.planetcocot.net/ |
|
Back to top |
|
 |
RenegadeC

Joined: 15 Oct 2004 Posts: 370 Location: The freezing hell; Canada
|
Posted: Tue Jun 12, 2007 4:30 pm Post subject: |
|
|
Here's some code I wrote for my CastleVania mod that may help. Explanation is in the descriptor section below: I'm mostly posting this here so you're able to see how I've made bmodel geometry entities go from solid -> non-solid and vice versa. Also it could be rewritten better (this is a few years old) but there you go. :)
void() jblock_think =
{
self.enemy = find(world, classname, "player");
if (self.enemy.origin_z > self.absmax_z + 23)
{
setorigin(self, self.origin);
self.solid = SOLID_BSP;
}
else
self.solid = SOLID_NOT;
frameskip(0.01); // switch to self.nextthink = time + 0.01;
// this is a TAoV leftover.
};
/*QUAKED func_jumpblock (0 .5 .8) ?
jump blocks are entities that are non solid when the player is below
and solid when above, allows a player to jump through and land on top
as seen in many platformer games
^/
void() func_jumpblock =
{
self.solid = SOLID_NOT;
self.movetype = MOVETYPE_PUSH;
self.classname = "jumpblock";
setmodel (self, self.model);
setsize (self, self.mins , self.maxs);
setorigin (self, self.origin);
self.think = jblock_think;
self.nextthink = time;
}; |
|
Back to top |
|
 |
CocoT

Joined: 14 Dec 2004 Posts: 599 Location: Belly-Gum
|
Posted: Tue Jun 12, 2007 5:04 pm Post subject: |
|
|
Thanks, Renegade! I'll have a look at it
For the moment, I've found an alternative to the "becomes non-solid just after the player stops touching it" thingy by simply making it lethal for the player to step on the same platform twice. So if anything, I'll just leave it like that, it does the trick. But that jblock_think code looks like it could work, too, so I'll try that
Thanks, everyone!  _________________ http://www.planetcocot.net/ |
|
Back to top |
|
 |
RenegadeC

Joined: 15 Oct 2004 Posts: 370 Location: The freezing hell; Canada
|
Posted: Tue Jun 12, 2007 5:31 pm Post subject: |
|
|
I forgot to mention, I'm not sure how JBlock would function in multiplayer since I wrote the CastleVania mod as singleplayer only therefore there may be a chance another player may get stuck inside the JBlock so if your mod is multiplayer you may want to keep that in mind. |
|
Back to top |
|
 |
CocoT

Joined: 14 Dec 2004 Posts: 599 Location: Belly-Gum
|
Posted: Tue Jun 12, 2007 7:37 pm Post subject: |
|
|
Thanks Actually, at the moment the (mini-)mod is single-player. And, well, it's likely to remain so, so no problem  _________________ http://www.planetcocot.net/ |
|
Back to top |
|
 |
|
|
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
|