Last active
January 27, 2023 16:45
-
-
Save uxdxdev/75de083136857134e031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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