Skip to content

Commit f25fbce

Browse files
bors[bot]C0D3D3V
andauthored
Merge #4972
4972: fix calculation of m_Angle of CCharacterCore r=def- a=C0D3D3V fixes #4969 fixes #4138 The problem of #4138 can be seen in the following picture: ![image](https://user-images.githubusercontent.com/14315968/162630858-2a1a813d-0551-4739-9f8a-9ed9017fdb9b.png) we have a strange angle circle, it was fixed in 0.7. For 0.7 to interpolate correctly between two network packets we should send the correct angle circle. The poblem from #4969 I have already described and follows directly from the wrong calculation. The PR fixes both problems. Here is a video, first I show how it behaves now in our client, then in a 0.7 client. https://user-images.githubusercontent.com/14315968/162630563-83847e3f-4d29-48d9-adc1-fb3ba20cc387.mp4 ## Checklist - [x] Tested the change ingame - [x] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [x] Considered possible null pointers and out of bounds array indexing - [x] Changed no physics that affect existing maps - [x] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: c0d3d3v <[email protected]>
2 parents 9c4c49e + 5ba4ddd commit f25fbce

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/game/gamecore.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,15 @@ void CCharacterCore::Tick(bool UseInput)
138138
m_Direction = m_Input.m_Direction;
139139

140140
// setup angle
141-
float a = 0;
142-
if(m_Input.m_TargetX == 0)
143-
a = atanf((float)m_Input.m_TargetY);
141+
float tmp_angle = atan2f(m_Input.m_TargetY, m_Input.m_TargetX);
142+
if(tmp_angle < -(pi / 2.0f))
143+
{
144+
m_Angle = (int)((tmp_angle + (2.0f * pi)) * 256.0f);
145+
}
144146
else
145-
a = atanf((float)m_Input.m_TargetY / (float)m_Input.m_TargetX);
146-
147-
if(m_Input.m_TargetX < 0)
148-
a = a + pi;
149-
150-
m_Angle = (int)(a * 256.0f);
147+
{
148+
m_Angle = (int)(tmp_angle * 256.0f);
149+
}
151150

152151
// handle jump
153152
if(m_Input.m_Jump)

src/game/server/entities/character.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,10 @@ void CCharacter::SnapCharacter(int SnappingClient, int ID)
11321132
return;
11331133

11341134
pCore->Write(reinterpret_cast<CNetObj_CharacterCore *>(static_cast<protocol7::CNetObj_CharacterCore *>(pCharacter)));
1135+
if(pCharacter->m_Angle > (int)(pi * 256.0f))
1136+
{
1137+
pCharacter->m_Angle -= (int)(2.0f * pi * 256.0f);
1138+
}
11351139

11361140
pCharacter->m_Tick = Tick;
11371141
pCharacter->m_Emote = Emote;

0 commit comments

Comments
 (0)