Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Alter Hase
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
float speed = 1; float tempx = sin(m_rot)*speed; float tempy = cos(m_rot)*speed; // bewegen float d1 = sqrt(pow(m_targetX-m_xPos,2)+pow(m_targetY-m_yPos,2)); // alte Position float d2 = sqrt(pow(m_targetX-(m_xPos+tempx),2)+pow(m_targetY-(m_yPos+tempy),2)); // neue Position float deg = acos(d2/d1); // links oder rechts m_xPos += tempy; m_yPos += tempx; if(deg < 2.0f*3.1415f*(180.0f/360.0f)) // links { m_rot -= 2.0f*3.1415f*(1.5f/360.0f); } else // rechts { m_rot += 2.0f*3.1415f*(1.5f/360.0f); } |
Zitat von »"Nexus"«
Oder dass die y-Richtung nach oben zeigt (wegen sin())?
C-/C++-Quelltext |
|
1 2 3 |
float d1 = sqrt(pow(m_targetX-m_xPos,2)+pow(m_targetY-m_yPos,2)); // abstand zwischen alte Pos und target float d2 = sqrt(pow(m_targetX-(m_xPos+tempx),2)+pow(m_targetY-(m_yPos+tempy),2)); // abstand zwischen neue Pos und target float deg = acos(d2/d1); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
float speed = 1; float tempx = sin(m_rot)*speed; float tempy = cos(m_rot)*speed; float lineA = distance(m_xPos+tempx, m_yPos+tempy, m_targetX, m_targetY); float deg = atan(speed/lineA); if(deg < 3.1415f) { m_rot += 0.1f; } else { m_rot -= 0.1f; } |
Werbeanzeige