diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2013-01-30 09:55:17 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2013-01-30 09:55:17 +0400 |
commit | 9191b783bb2bc1a2d4be2b2cd215735e68353a56 (patch) | |
tree | 8440c8b155a69580b358ded134bad49e27bb8eba /source/gameengine/Ketsji/KX_CharacterWrapper.cpp | |
parent | 26ee2a1f79c3513ca9eaeb6a3a8d855c37088468 (diff) |
BGE: Some various changes to make moving the character physics type easier:
* Undoing the previous applyMovement() changes for characters. This was causing bugs for the Motion Actuator.
* Creating a Character Motion type for the Motion Actuator with specific controls for characters. This includes moving, rotating and jumping.
* Adding a KX_CharacterWrapper.walkDirection to set the character's direction and speed.
Note, this also resolves the following bugs:
[#33585] "Setting dLoc of motion actuator [0,0,0] via python won't stop object" reported by Manuel Bellersen (urfoex)
[#33503] "Character physics type won´t accept more than one motion anymore" reported by Mr Larodos
Diffstat (limited to 'source/gameengine/Ketsji/KX_CharacterWrapper.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_CharacterWrapper.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/source/gameengine/Ketsji/KX_CharacterWrapper.cpp b/source/gameengine/Ketsji/KX_CharacterWrapper.cpp index 64bbbb7d344..a669bdd2586 100644 --- a/source/gameengine/Ketsji/KX_CharacterWrapper.cpp +++ b/source/gameengine/Ketsji/KX_CharacterWrapper.cpp @@ -5,6 +5,7 @@ #include "KX_CharacterWrapper.h" #include "PHY_ICharacter.h" +#include "KX_PyMath.h" KX_CharacterWrapper::KX_CharacterWrapper(PHY_ICharacter* character) : PyObjectPlus(), @@ -47,6 +48,7 @@ PyAttributeDef KX_CharacterWrapper::Attributes[] = { KX_PYATTRIBUTE_RW_FUNCTION("gravity", KX_CharacterWrapper, pyattr_get_gravity, pyattr_set_gravity), KX_PYATTRIBUTE_RW_FUNCTION("maxJumps", KX_CharacterWrapper, pyattr_get_max_jumps, pyattr_set_max_jumps), KX_PYATTRIBUTE_RO_FUNCTION("jumpCount", KX_CharacterWrapper, pyattr_get_jump_count), + KX_PYATTRIBUTE_RW_FUNCTION("walkDirection", KX_CharacterWrapper, pyattr_get_walk_dir, pyattr_set_walk_dir), { NULL } //Sentinel }; @@ -108,6 +110,33 @@ PyObject *KX_CharacterWrapper::pyattr_get_jump_count(void *self_v, const KX_PYAT return PyLong_FromLong(self->m_character->GetJumpCount()); } +PyObject *KX_CharacterWrapper::pyattr_get_walk_dir(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v); + PHY__Vector3 vec = self->m_character->GetWalkDirection(); + MT_Vector3 retval = MT_Vector3(vec[0], vec[1], vec[2]); + + return PyObjectFrom(retval); +} + +int KX_CharacterWrapper::pyattr_set_walk_dir(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v); + MT_Vector3 dir; + if (!PyVecTo(value, dir)) { + PyErr_SetString(PyExc_TypeError, "KX_CharacterWrapper.walkDirection: expected a vector"); + return PY_SET_ATTR_FAIL; + } + + PHY__Vector3 vec; + vec[0] = dir[0]; + vec[1] = dir[1]; + vec[2] = dir[2]; + + self->m_character->SetWalkDirection(vec); + return PY_SET_ATTR_SUCCESS; +} + PyMethodDef KX_CharacterWrapper::Methods[] = { KX_PYMETHODTABLE_NOARGS(KX_CharacterWrapper, jump), {NULL,NULL} //Sentinel |