Jump to content

[SOLVED] object movement according to axis of its parent


photo

Recommended Posts

How to know direction of object parent to move object along its forward.Is there any way to get related parent forward direction in Unigine?

For example if i move the turret according to given rotation and its child object available on it, so how can i move this object along to turrets forward direction.The most important point is; i can not change its x,y and z axis with set position function, it should move without giving its x,y or z axis accordig to forward direction of the turret. 

Example code;

float objectifps;
const float mObjectMovSpeed = 3.0f;
float mforward_direction = Unigine::Math::Vec3(0.0f, -1.0f, 0.0f); // it moves on y direction with this vector, but i want to move it according to head of turret direction.

mmissileifps = 0.05;
mObjectLeft->setWorldPosition(mObjectLeft->getWorldPosition()+mforward_direction*mObjectMovSpeed*objectifps);

İt moves along y axis, i couldn't manage objects movement according to direction of turret head.

Edited by burakdogancay
Link to comment

try something like this

NodePtr mObjectLeft = .....; // original node

NodePtr parent = mObjectLeft->getParent();
if (parent)
{
	vec3 mforward_direction = parent->getWorldDirection(Math::AXIS_Y);
	mObjectLeft->setWorldPosition(mObjectLeft->getWorldPosition() + mforward_direction * mObjectMovSpeed * Game::get()->getIFps());
}

 

Link to comment
  • morbid changed the title to [SOLVED] object movement according to axis of its parent
×
×
  • Create New...