mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-26 04:12:41 +01:00
Reset vehicles and pedestrians that fall out of the map
This commit is contained in:
parent
81f265ba3a
commit
802a746211
@ -79,6 +79,12 @@ public:
|
|||||||
void setCurrentVehicle(GTAVehicle *value, size_t seat);
|
void setCurrentVehicle(GTAVehicle *value, size_t seat);
|
||||||
|
|
||||||
virtual bool takeDamage(const DamageInfo& damage);
|
virtual bool takeDamage(const DamageInfo& damage);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the Actor to the nearest AI Graph node
|
||||||
|
* (taking into account the current vehicle)
|
||||||
|
*/
|
||||||
|
void resetToAINode();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,6 +41,8 @@ public:
|
|||||||
|
|
||||||
virtual ~GTAVehicle();
|
virtual ~GTAVehicle();
|
||||||
|
|
||||||
|
void setPosition(const glm::vec3& pos);
|
||||||
|
|
||||||
glm::vec3 getPosition() const;
|
glm::vec3 getPosition() const;
|
||||||
|
|
||||||
glm::quat getRotation() const;
|
glm::quat getRotation() const;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <renderwure/engine/GTAEngine.hpp>
|
#include <renderwure/engine/GTAEngine.hpp>
|
||||||
#include <renderwure/engine/Animator.hpp>
|
#include <renderwure/engine/Animator.hpp>
|
||||||
#include <renderwure/objects/GTAVehicle.hpp>
|
#include <renderwure/objects/GTAVehicle.hpp>
|
||||||
|
#include <boost/concept_check.hpp>
|
||||||
|
|
||||||
GTACharacter::GTACharacter(GTAEngine* engine, const glm::vec3& pos, const glm::quat& rot, Model* model, std::shared_ptr<CharacterData> data)
|
GTACharacter::GTACharacter(GTAEngine* engine, const glm::vec3& pos, const glm::quat& rot, Model* model, std::shared_ptr<CharacterData> data)
|
||||||
: GTAObject(engine, pos, rot, model),
|
: GTAObject(engine, pos, rot, model),
|
||||||
@ -42,7 +43,8 @@ void GTACharacter::createActor(const glm::vec3& size)
|
|||||||
physShape = new btCapsuleShapeZ(size.x, size.z);
|
physShape = new btCapsuleShapeZ(size.x, size.z);
|
||||||
physObject->setCollisionShape(physShape);
|
physObject->setCollisionShape(physShape);
|
||||||
physObject->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
|
physObject->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||||
physCharacter = new btKinematicCharacterController(physObject, physShape, 3.5f, 2);
|
physCharacter = new btKinematicCharacterController(physObject, physShape, 0.2f, 2);
|
||||||
|
physCharacter->setVelocityForTimeInterval(btVector3(1.f, 1.f, 0.f), 1.f);
|
||||||
|
|
||||||
engine->dynamicsWorld->addCollisionObject(physObject, btBroadphaseProxy::KinematicFilter, btBroadphaseProxy::StaticFilter);
|
engine->dynamicsWorld->addCollisionObject(physObject, btBroadphaseProxy::KinematicFilter, btBroadphaseProxy::StaticFilter);
|
||||||
engine->dynamicsWorld->addAction(physCharacter);
|
engine->dynamicsWorld->addAction(physCharacter);
|
||||||
@ -107,6 +109,11 @@ void GTACharacter::tick(float dt)
|
|||||||
}
|
}
|
||||||
animator->tick(dt);
|
animator->tick(dt);
|
||||||
updateCharacter();
|
updateCharacter();
|
||||||
|
|
||||||
|
// Ensure the character doesn't need to be reset
|
||||||
|
if(getPosition().z < -100.f) {
|
||||||
|
resetToAINode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTACharacter::updateCharacter()
|
void GTACharacter::updateCharacter()
|
||||||
@ -238,3 +245,33 @@ bool GTACharacter::takeDamage(const GTAObject::DamageInfo& dmg)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GTACharacter::resetToAINode()
|
||||||
|
{
|
||||||
|
auto nodes = engine->aigraph.nodes;
|
||||||
|
bool vehicleNode = !! getCurrentVehicle();
|
||||||
|
GTAAINode* nearest = nullptr; float d = std::numeric_limits<float>::max();
|
||||||
|
for(auto it = nodes.begin(); it != nodes.end(); ++it) {
|
||||||
|
if(vehicleNode) {
|
||||||
|
if((*it)->type == GTAAINode::Pedestrian) continue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if((*it)->type == GTAAINode::Vehicle) continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
float dist = glm::length((*it)->position - getPosition());
|
||||||
|
if(dist < d) {
|
||||||
|
nearest = *it;
|
||||||
|
d = dist;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(nearest) {
|
||||||
|
if(vehicleNode) {
|
||||||
|
getCurrentVehicle()->setPosition(nearest->position + glm::vec3(0.f, 0.f, 2.5f));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setPosition(nearest->position + glm::vec3(0.f, 0.f, 2.5f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -112,6 +112,16 @@ GTAVehicle::~GTAVehicle()
|
|||||||
ejectAll();
|
ejectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GTAVehicle::setPosition(const glm::vec3& pos)
|
||||||
|
{
|
||||||
|
GTAObject::setPosition(pos);
|
||||||
|
if(physBody) {
|
||||||
|
auto t = physBody->getWorldTransform();
|
||||||
|
t.setOrigin(btVector3(pos.x, pos.y, pos.z));
|
||||||
|
physBody->setWorldTransform(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glm::vec3 GTAVehicle::getPosition() const
|
glm::vec3 GTAVehicle::getPosition() const
|
||||||
{
|
{
|
||||||
if(physBody) {
|
if(physBody) {
|
||||||
|
Loading…
Reference in New Issue
Block a user