Skip to content

Instantly share code, notes, and snippets.

@uxdxdev
Last active January 27, 2023 16:45
Show Gist options
  • Save uxdxdev/75de083136857134e031 to your computer and use it in GitHub Desktop.
Save uxdxdev/75de083136857134e031 to your computer and use it in GitHub Desktop.
void Cannon::Update(float dt)
{
if (m_pTarget != nullptr && m_pSprite != nullptr)
{
cocos2d::Vec2 thisPosition;
thisPosition = m_pSprite->getPosition();
m_TargetPosition = WorldManager::getInstance()->GetCenter(m_pTarget);
float angle = atan2(thisPosition.x - m_TargetPosition.x, thisPosition.y - m_TargetPosition.y);
angle = angle * (180.0f / PI);
if (angle < 0)
{
angle += 360.0f;
}
m_pSprite->setRotation(angle + 180.0f);
}
ShootTimer(dt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment