@@ -12,46 +12,56 @@ input.setControlSwitch(input.CONTROL_SWITCH.Magic, false)
12
12
input .setControlSwitch (input .CONTROL_SWITCH .VanityMode , false )
13
13
input .setControlSwitch (input .CONTROL_SWITCH .ViewMode , false )
14
14
15
- testing .registerLocalTest (' playerMovement ' ,
15
+ testing .registerLocalTest (' playerRotation ' ,
16
16
function ()
17
- local startTime = core .getSimulationTime ()
18
- local pos = self .position
19
-
20
- while core .getSimulationTime () < startTime + 0.5 do
17
+ local endTime = core .getSimulationTime () + 1
18
+ while core .getSimulationTime () < endTime do
21
19
self .controls .jump = false
22
20
self .controls .run = true
23
21
self .controls .movement = 0
24
22
self .controls .sideMovement = 0
25
- local progress = (core .getSimulationTime () - startTime ) / 0.5
26
- self .controls .yawChange = util .normalizeAngle (math.rad (90 ) * progress - self .rotation .z )
23
+ self .controls .yawChange = util .normalizeAngle (math.rad (90 ) - self .rotation .z ) * 0.5
27
24
coroutine.yield ()
28
25
end
29
26
testing .expectEqualWithDelta (self .rotation .z , math.rad (90 ), 0.05 , ' Incorrect rotation' )
27
+ end )
30
28
31
- while core .getSimulationTime () < startTime + 1.5 do
29
+ testing .registerLocalTest (' playerForwardRunning' ,
30
+ function ()
31
+ local startPos = self .position
32
+ local endTime = core .getSimulationTime () + 1
33
+ while core .getSimulationTime () < endTime do
32
34
self .controls .jump = false
33
35
self .controls .run = true
34
36
self .controls .movement = 1
35
37
self .controls .sideMovement = 0
36
38
self .controls .yawChange = 0
37
39
coroutine.yield ()
38
40
end
39
- direction = (self .position - pos ) / types .Actor .runSpeed (self )
40
- testing .expectEqualWithDelta (direction .x , 1 , 0.1 , ' Run forward, X coord' )
41
- testing .expectEqualWithDelta (direction .y , 0 , 0.1 , ' Run forward, Y coord' )
41
+ local direction , distance = (self .position - startPos ):normalize ()
42
+ local normalizedDistance = distance / types .Actor .runSpeed (self )
43
+ testing .expectEqualWithDelta (normalizedDistance , 1 , 0.2 , ' Normalized forward runned distance' )
44
+ testing .expectEqualWithDelta (direction .x , 0 , 0.1 , ' Run forward, X coord' )
45
+ testing .expectEqualWithDelta (direction .y , 1 , 0.1 , ' Run forward, Y coord' )
46
+ end )
42
47
43
- pos = self .position
44
- while core .getSimulationTime () < startTime + 2.5 do
48
+ testing .registerLocalTest (' playerDiagonalWalking' ,
49
+ function ()
50
+ local startPos = self .position
51
+ local endTime = core .getSimulationTime () + 1
52
+ while core .getSimulationTime () < endTime do
45
53
self .controls .jump = false
46
54
self .controls .run = false
47
55
self .controls .movement = - 1
48
56
self .controls .sideMovement = - 1
49
57
self .controls .yawChange = 0
50
58
coroutine.yield ()
51
59
end
52
- direction = (self .position - pos ) / types .Actor .walkSpeed (self )
60
+ local direction , distance = (self .position - startPos ):normalize ()
61
+ local normalizedDistance = distance / types .Actor .walkSpeed (self )
62
+ testing .expectEqualWithDelta (normalizedDistance , 1 , 0.2 , ' Normalized diagonally walked distance' )
53
63
testing .expectEqualWithDelta (direction .x , - 0.707 , 0.1 , ' Walk diagonally, X coord' )
54
- testing .expectEqualWithDelta (direction .y , 0.707 , 0.1 , ' Walk diagonally, Y coord' )
64
+ testing .expectEqualWithDelta (direction .y , - 0.707 , 0.1 , ' Walk diagonally, Y coord' )
55
65
end )
56
66
57
67
return {
@@ -60,4 +70,3 @@ return {
60
70
},
61
71
eventHandlers = testing .eventHandlers
62
72
}
63
-
0 commit comments