Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorge Bernal <jbernalmartinez@gmail.com>2015-02-19 01:24:02 +0300
committerJorge Bernal <jbernalmartinez@gmail.com>2015-02-19 01:24:02 +0300
commit5d0696052a00ca80043852ca891b1bbe0b70ff1b (patch)
treebbc455ac8d262452748e1a220fa2277351ac15b3 /source/gameengine
parentbd5154bb2c642d09b95ff8a2d71e404faa6f6f84 (diff)
BGE: Fix T41502 Path following jumping
New Lock Z velocity parameter was added. This parameter avoid the micro-jumping. By default it is actived except when you load an old file that it is deactived to keep former behaviour. Additionally it was solved another issue related with the acceleration: That is the acceleration value was not taked into account and we had always the maximum linear velocity from the beginning of movement. Now the acceleration is taken into account until we reach the maximum velocity. When you load an old file, the acceleration value is set to the maximum range (1000.f). This way we simulate a maximum velocity constant from the beginning of movement (former behaviour). {F142195} Reviewers: moguri, dfelinto, campbellbarton Reviewed By: campbellbarton Subscribers: sergey Differential Revision: https://developer.blender.org/D1074
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/Converter/KX_ConvertActuators.cpp3
-rw-r--r--source/gameengine/Ketsji/KX_SteeringActuator.cpp25
-rw-r--r--source/gameengine/Ketsji/KX_SteeringActuator.h4
3 files changed, 23 insertions, 9 deletions
diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp
index f6ed3366625..ff4b5a61d12 100644
--- a/source/gameengine/Converter/KX_ConvertActuators.cpp
+++ b/source/gameengine/Converter/KX_ConvertActuators.cpp
@@ -1087,11 +1087,12 @@ void BL_ConvertActuators(const char* maggiename,
bool enableVisualization = (stAct->flag & ACT_STEERING_ENABLEVISUALIZATION) !=0;
short facingMode = (stAct->flag & ACT_STEERING_AUTOMATICFACING) ? stAct->facingaxis : 0;
bool normalup = (stAct->flag & ACT_STEERING_NORMALUP) !=0;
+ bool lockzvel = (stAct->flag & ACT_STEERING_LOCKZVEL) !=0;
KX_SteeringActuator *tmpstact
= new KX_SteeringActuator(gameobj, mode, targetob, navmeshob,stAct->dist,
stAct->velocity, stAct->acceleration, stAct->turnspeed,
selfTerminated, stAct->updateTime,
- scene->GetObstacleSimulation(), facingMode, normalup, enableVisualization);
+ scene->GetObstacleSimulation(), facingMode, normalup, enableVisualization, lockzvel);
baseact = tmpstact;
break;
}
diff --git a/source/gameengine/Ketsji/KX_SteeringActuator.cpp b/source/gameengine/Ketsji/KX_SteeringActuator.cpp
index ff192299702..10d4273a2b4 100644
--- a/source/gameengine/Ketsji/KX_SteeringActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SteeringActuator.cpp
@@ -41,7 +41,7 @@
/* Native functions */
/* ------------------------------------------------------------------------- */
-KX_SteeringActuator::KX_SteeringActuator(SCA_IObject *gameobj,
+KX_SteeringActuator::KX_SteeringActuator(SCA_IObject *gameobj,
int mode,
KX_GameObject *target,
KX_GameObject *navmesh,
@@ -54,7 +54,8 @@ KX_SteeringActuator::KX_SteeringActuator(SCA_IObject *gameobj,
KX_ObstacleSimulation* simulation,
short facingmode,
bool normalup,
- bool enableVisualization)
+ bool enableVisualization,
+ bool lockzvel)
: SCA_IActuator(gameobj, KX_ACT_STEERING),
m_target(target),
m_mode(mode),
@@ -72,6 +73,7 @@ KX_SteeringActuator::KX_SteeringActuator(SCA_IObject *gameobj,
m_normalUp(normalup),
m_pathLen(0),
m_pathUpdatePeriod(pathUpdatePeriod),
+ m_lockzvel(lockzvel),
m_wayPointIdx(-1),
m_steerVec(MT_Vector3(0, 0, 0))
{
@@ -261,19 +263,19 @@ bool KX_SteeringActuator::Update(double curtime, bool frame)
if (apply_steerforce)
{
+ MT_Vector3 newvel;
bool isdyna = obj->IsDynamic();
if (isdyna)
m_steerVec.z() = 0;
if (!m_steerVec.fuzzyZero())
m_steerVec.normalize();
- MT_Vector3 newvel = m_velocity*m_steerVec;
//adjust velocity to avoid obstacles
if (m_simulation && m_obstacle /*&& !newvel.fuzzyZero()*/)
{
if (m_enableVisualization)
KX_RasterizerDrawDebugLine(mypos, mypos + newvel, MT_Vector3(1.0, 0.0, 0.0));
- m_simulation->AdjustObstacleVelocity(m_obstacle, m_mode!=KX_STEERING_PATHFOLLOWING ? m_navmesh : NULL,
+ m_simulation->AdjustObstacleVelocity(m_obstacle, m_mode!=KX_STEERING_PATHFOLLOWING ? m_navmesh : NULL,
newvel, m_acceleration*delta, m_turnspeed/180.0f*M_PI*delta);
if (m_enableVisualization)
KX_RasterizerDrawDebugLine(mypos, mypos + newvel, MT_Vector3(0.0, 1.0, 0.0));
@@ -282,10 +284,18 @@ bool KX_SteeringActuator::Update(double curtime, bool frame)
HandleActorFace(newvel);
if (isdyna)
{
- //temporary solution: set 2D steering velocity directly to obj
- //correct way is to apply physical force
+ //TODO: Take into account angular velocity on turns
MT_Vector3 curvel = obj->GetLinearVelocity();
- newvel.z() = curvel.z();
+
+ newvel = (curvel.length() * m_steerVec) + (m_acceleration * delta) * m_steerVec;
+ if (newvel.length2() >= (m_velocity * m_velocity))
+ newvel = m_velocity * m_steerVec;
+
+ if (m_lockzvel)
+ newvel.z() = 0.0f;
+ else
+ newvel.z() = curvel.z();
+
obj->setLinearVelocity(newvel, false);
}
else
@@ -554,6 +564,7 @@ PyAttributeDef KX_SteeringActuator::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("steeringVec", KX_SteeringActuator, pyattr_get_steeringVec),
KX_PYATTRIBUTE_SHORT_RW("facingMode", 0, 6, true, KX_SteeringActuator, m_facingMode),
KX_PYATTRIBUTE_INT_RW("pathUpdatePeriod", -1, 100000, true, KX_SteeringActuator, m_pathUpdatePeriod),
+ KX_PYATTRIBUTE_BOOL_RW("lockZVelocity", KX_SteeringActuator, m_lockzvel),
{ NULL } //Sentinel
};
diff --git a/source/gameengine/Ketsji/KX_SteeringActuator.h b/source/gameengine/Ketsji/KX_SteeringActuator.h
index 1e8ac9a54f0..3273471c166 100644
--- a/source/gameengine/Ketsji/KX_SteeringActuator.h
+++ b/source/gameengine/Ketsji/KX_SteeringActuator.h
@@ -62,6 +62,7 @@ class KX_SteeringActuator : public SCA_IActuator
int m_pathLen;
int m_pathUpdatePeriod;
double m_pathUpdateTime;
+ bool m_lockzvel;
int m_wayPointIdx;
MT_Matrix3x3 m_parentlocalmat;
MT_Vector3 m_steerVec;
@@ -89,7 +90,8 @@ public:
KX_ObstacleSimulation* simulation,
short facingmode,
bool normalup,
- bool enableVisualization);
+ bool enableVisualization,
+ bool lockzvel);
virtual ~KX_SteeringActuator();
virtual bool Update(double curtime, bool frame);