Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/weapons/projectiles/Projectile.cc @ 10532

Last change on this file since 10532 was 10287, checked in by landauf, 10 years ago

use dynamic physics for projectiles. this seems to avoid 'tunneling' (if the projectile moves through an opponent without colliding) even with low FPS. projectiles now also collide with static entities.

  • Property svn:eol-style set to native
File size: 2.6 KB
RevLine 
[2099]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
[8706]25 *      simonmie
[2099]26 *
27 */
28
[8855]29/**
30    @file Projectile.h
31    @brief Implementation of the Projectile class.
32*/
33
[2099]34#include "Projectile.h"
35
[9667]36#include "core/config/ConfigValueIncludes.h"
[2099]37#include "core/CoreIncludes.h"
[3196]38#include "core/GameMode.h"
[7284]39#include "core/command/Executor.h"
[8855]40
[3196]41#include "objects/collisionshapes/SphereCollisionShape.h"
[5735]42#include "worldentities/pawns/Pawn.h"
[2099]43
44namespace orxonox
45{
[9667]46    RegisterClass(Projectile);
[3105]47
[9667]48    Projectile::Projectile(Context* context) : MovableEntity(context), BasicProjectile()
[2099]49    {
50        RegisterObject(Projectile);
51
52        this->setConfigValues();
53
[2662]54        // Get notification about collisions
[2896]55        if (GameMode::isMaster())
[2099]56        {
[8855]57            this->setMass(1.0f);
[2662]58            this->enableCollisionCallback();
[3105]59            this->setCollisionResponse(false);
[10287]60            this->setCollisionType(Dynamic);
[2662]61
[9667]62            SphereCollisionShape* shape = new SphereCollisionShape(this->getContext());
[8855]63            shape->setRadius(20.0f);
[2662]64            this->attachCollisionShape(shape);
65
[8855]66            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
[2099]67        }
68    }
69
70    Projectile::~Projectile()
71    {
72    }
73
74    void Projectile::setConfigValues()
75    {
[8855]76        SetConfigValue(lifetime_, 4.0f).description("The time in seconds a projectile stays alive");
[2099]77    }
78
79
80    void Projectile::tick(float dt)
81    {
[2809]82        SUPER(Projectile, tick, dt);
[2099]83
84        if (!this->isActive())
85            return;
86
[8855]87        this->destroyCheck();
[2662]88    }
89
[10216]90    bool Projectile::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
[2662]91    {
[10216]92        return this->processCollision(otherObject, contactPoint, cs);
[2099]93    }
94
95}
Note: See TracBrowser for help on using the repository browser.