if (CInput::getInstance().getKeyboard()->isKeyDown((int)'W'))
{
//play sound
CTransformComponent * pTransform=m_pGameObjectManager->findGameObject("Player")->getTransform();
pTransform->translate(0.0f,0.0f,m_Timer.getElapsedTime()*4);
CTransformComponent * pTransform2=m_pGameObjectManager->findGameObject("Camera")->getTransform();
pTransform2->translate(0.0f,0.0f,m_Timer.getElapsedTime()*4);
}
else if (CInput::getInstance().getKeyboard()->isKeyDown((int)'S'))
{
//play sound
CTransformComponent * pTransform=m_pGameObjectManager->findGameObject("Player")->getTransform();
pTransform->translate(0.0f,0.0f,m_Timer.getElapsedTime()*-4);
CTransformComponent * pTransform2=m_pGameObjectManager->findGameObject("Camera")->getTransform();
pTransform2->translate(0.0f,0.0f,m_Timer.getElapsedTime()*-4);
}
if (CInput::getInstance().getKeyboard()->isKeyDown((int)'D'))
{
//play sound
CTransformComponent * pTransform=m_pGameObjectManager->findGameObject("Player")->getTransform();
pTransform->rotate(0.0f,m_Timer.getElapsedTime()*2,0.0f);
CTransformComponent * pTransform2=m_pGameObjectManager->findGameObject("Sky")->getTransform();
pTransform2->rotate(0.0f,m_Timer.getElapsedTime()*2,0.0f);
}
else if (CInput::getInstance().getKeyboard()->isKeyDown((int)'A'))
{
//play sound
CTransformComponent * pTransform=m_pGameObjectManager->findGameObject("Player")->getTransform();
pTransform->rotate(0.0f,m_Timer.getElapsedTime()*-2,0.0f);
CTransformComponent * pTransform2=m_pGameObjectManager->findGameObject("Sky")->getTransform();
pTransform2->rotate(0.0f,m_Timer.getElapsedTime()*-2,0.0f);
}
5 Replies - 442 Views - Last Post: 02 December 2012 - 02:47 PM
#1
Problem updating forward direction after rotation. C++
Posted 29 November 2012 - 10:44 AM
Hey, having a bit of a problem with a game object I am trying to manipulate. Basically I use the "A" and "D" keys to rotate the object anti-clockwise and clockwise respectively. I also use the keys "W" and "S" to translate the object back and forward, this is working up until the point that the object is rotated. After this has occurred the object will only continue to move in the same axis. I understand why this is happening as I am not updating the translate with the rotation, anyone know how I can do this with my code?
Replies To: Problem updating forward direction after rotation. C++
#2
Re: Problem updating forward direction after rotation. C++
Posted 29 November 2012 - 02:04 PM
It's not clear what you're asking. What I am thinking is that you simply restore your axes after performing the translation. Does that seem right?
#3
Re: Problem updating forward direction after rotation. C++
Posted 29 November 2012 - 11:47 PM
ButchDean, on 29 November 2012 - 02:04 PM, said:
It's not clear what you're asking. What I am thinking is that you simply restore your axes after performing the translation. Does that seem right?
I guess that might work. Basically when I rotate the vehicle, I would like it to move in the new direction it is facing when I press the forward button rather than continue moving along the same axis
#4
Re: Problem updating forward direction after rotation. C++
Posted 30 November 2012 - 11:14 AM
So you're after a motion that you see in a racing game, for instance? If you are there is a novel solution.
In racing games the vehicle you control is actually stationary and the world around is rotated and translated. This removes a lot of complexity. Would that approach be applicable to solving your problem?
In racing games the vehicle you control is actually stationary and the world around is rotated and translated. This removes a lot of complexity. Would that approach be applicable to solving your problem?
#5
Re: Problem updating forward direction after rotation. C++
Posted 02 December 2012 - 01:26 PM
Unfortunately that isn't really a practical solution as there are other vehicles that move independently that the player has to attack. The vehicle needs to be able to rotate on the y axis which it does already, but once it has rotated it is facing a new direction. when the player presses the forward key I would like the vehicle to move in the direction it is facing
#6
Re: Problem updating forward direction after rotation. C++
Posted 02 December 2012 - 02:47 PM
How did you work out that what I suggested is not a practical solution? Have you thought about how you would approach it?
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|