MCPcopy Create free account
hub / github.com/assaultcube/AC / moveplayer

Function moveplayer

source/src/physics.cpp:398–773  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

396FVARP(flyspeed, 1.0, 2.0, 5.0);
397
398void moveplayer(physent *pl, int moveres, bool local, int curtime)
399{
400 bool water = false;
401 const bool editfly = pl->state==CS_EDITING;
402 const bool specfly = pl->type==ENT_PLAYER && ((playerent *)pl)->spectatemode==SM_FLY;
403 const bool isfly = editfly || specfly;
404
405 vec d; // vector of direction we ideally want to move in
406
407 float drop = 0, rise = 0;
408
409 if(pl->type==ENT_BOUNCE)
410 {
411 bounceent* bounce = (bounceent *) pl;
412 water = waterlevel > pl->o.z;
413
414 const float speed = curtime*pl->maxspeed/(water ? 2000.0f : 1000.0f);
415 const float friction = water ? 20.0f : (pl->onfloor || isfly ? 6.0f : 30.0f);
416 const float fpsfric = max(friction*20.0f/curtime, 1.0f);
417
418 if(pl->onfloor) // apply friction
419 {
420 pl->vel.mul(fpsfric-1);
421 pl->vel.div(fpsfric);
422 }
423 else // apply gravity
424 {
425 const float CUBES_PER_METER = 4; // assumes 4 cubes make up 1 meter
426 const float BOUNCE_MASS = 0.5f; // sane default mass of 0.5 kg
427 const float GRAVITY = BOUNCE_MASS*9.81f/CUBES_PER_METER/1000.0f;
428 bounce->vel.z -= GRAVITY*curtime;
429 }
430
431 d = bounce->vel;
432 d.mul(speed);
433 if(water) d.div(6.0f); // incorrect
434
435 // rotate
436 float rotspeed = bounce->rotspeed*d.magnitude();
437 pl->pitch = fmod(pl->pitch+rotspeed, 360.0f);
438 pl->yaw = fmod(pl->yaw+rotspeed, 360.0f);
439 }
440 else // fake physics for player ents to create _the_ cube movement (tm)
441 {
442 const int timeinair = pl->timeinair;
443 int move = intermission || (pl->onladder && !pl->onfloor && pl->move == -1) ? 0 : pl->move; // movement on ladder
444 if(!editfly) water = waterlevel > pl->o.z - 0.5f;
445
446 float chspeed = (pl->onfloor || pl->onladder || !pl->crouchedinair) ? 0.4f : 1.0f;
447
448 const bool crouching = pl->crouching || (pl->eyeheight < pl->maxeyeheight && pl->eyeheight > 1.1f);
449 const float speed = curtime/(water ? 2000.0f : 1000.0f)*pl->maxspeed*(crouching && pl->state != CS_EDITING ? chspeed : 1.0f)*(pl==player1 && isfly ? flyspeed : 1.0f);
450 const float friction = water ? 20.0f : (pl->onfloor || isfly ? 6.0f : (pl->onladder ? 1.5f : 30.0f));
451 const float fpsfric = max(friction/curtime*20.0f, 1.0f);
452
453 d.x = (float)(move*cosf(RAD*(pl->yaw-90)));
454 d.y = (float)(move*sinf(RAD*(pl->yaw-90)));
455 d.z = 0.0f;

Callers 8

movebounceentFunction · 0.85
recomputecameraFunction · 0.85
moveoutsidebboxMethod · 0.85
flagdroppedFunction · 0.85
movelocalplayerFunction · 0.85
predictplayerFunction · 0.85
moveotherplayersFunction · 0.85
ThinkMethod · 0.85

Calls 15

maxFunction · 0.85
vecClass · 0.85
collideFunction · 0.85
fixcamerarangeFunction · 0.85
updatecrouchFunction · 0.85
resizephysentFunction · 0.85
interpposFunction · 0.85
mulMethod · 0.80
magnitudeMethod · 0.80
magnitudexyMethod · 0.80
playsoundcMethod · 0.80
dotxyMethod · 0.80

Tested by

no test coverage detected