
Any suggestions ? As I said, I am using FTEQW and I'm OK with a solution that works only on it (I kinda gave up on Darkplaces at least for this project).
Code: Select all
pseudocode:
void myroomtriggerfunc()
{
if(other.classname == blah){
other.customgrav = TRUE;
}
}
void CSQC_InputFrame()
{
cycle trough all entities in map or (probably better, because we're inside a room) by radius
if(e.customgrav){
tracebox(e.origin,e.mins,e.maxs,e.origin+e.velocity,0,e);
//here all the crazy stuff you want for gravity..I dunno, probably invert self.velocity_z or add random velocity + rotation..dunno
e.origin = trace_endpos;
}
}
Code: Select all
void Player_Think()
{
//all the crazy stuff goes here (you could add here the "if .customgrav field == TRUE block")
self.nextthink = time + PHYSICS_TIME_UPDATE;
self.think = Player_Think;
}
void Physics_CustomPhys()
{
Player_Think();
}
void Player_Init()
{
player = spawn();
player.customphysics = Physics_CustomPhys;
player.nextthink = time +1 ;
player.think = Player_Think;
}
Code: Select all
void() MyCustomMovetype_Bounce =
{
if(self.nextthink && time > self.nextthink) // you could even make it into a loop, if you're paranoid about framerate slippage.
{
self.nextthink = 0;
self.think();
}
if (self.flags & FL_ONGROUND)
return; //no need to do anything
self.velocity_z -= self.gravity * autocvar_sv_gravity * frametime; //apply lame gravity
traceline(self.origin, self.origin + self.velocity * frametime, FALSE, self); //figure out where we go
self.velocity -= (self.velocity * trace_plane_normal) * trace_plane_normal * 1.5; //bounce off what we hit. use *1 to just slide. *2 to retain full speed.
if (trace_fraction < 1 && trace_plane_normal_z > 0.7 && vlen(self.velocity) < 60)
{ //looks like we hit the floor, and we're not travelling fast enough to bounce much.
self.flags |= FL_ONGROUND; //stop using tracelines and all this extra logic.
self.velocity = '0 0 0';
self.groundentity = trace_ent;
}
local float frac = trace_fraction; //touchtriggers can call trigger touches and they can call traceline...
local entity touchee = trace_ent;
touchtriggers(self, trace_endpos); //and actually moves there like setorigin and update pvs stuff, but also at the same time checks for triggers (like trigger_setgravity) then calls their touch functions.
if (frac < 1)
{
if (self.touch)
{ //we touched something, maybe world
other = touchee ;
self.touch();
}
if (trace_ent.touch)
{ //touching is mutual.
other = self;
self = touchee ;
self.touch();
}
}
};