246
edits
Icecream17 (talk | contribs) No edit summary |
Icecream17 (talk | contribs) (this code is so indirect) |
||
Line 55: | Line 55: | ||
# finally, play the flying sound (adjust sound for speed) | # finally, play the flying sound (adjust sound for speed) | ||
Notice that there is no code handling air steps for ledge grabbing or hanging on a ceiling, so such transitions are impossible. | Notice that there is no code handling air steps for ledge grabbing or hanging on a ceiling, so such transitions are impossible. | ||
===update_flying=== | |||
I am too lazy to describe the exact details of <code>update_flying</code>, so here is the code | |||
<syntaxhighlight lang="c"> | |||
void update_flying(struct MarioState *m) { | |||
UNUSED u8 filler[4]; | |||
update_flying_pitch(m); | |||
update_flying_yaw(m); | |||
m->forwardVel -= 2.0f * ((f32) m->faceAngle[0] / 0x4000) + 0.1f; | |||
m->forwardVel -= 0.5f * (1.0f - coss(m->angleVel[1])); | |||
if (m->forwardVel < 0.0f) { | |||
m->forwardVel = 0.0f; | |||
} | |||
if (m->forwardVel > 16.0f) { | |||
m->faceAngle[0] += (m->forwardVel - 32.0f) * 6.0f; | |||
} else if (m->forwardVel > 4.0f) { | |||
m->faceAngle[0] += (m->forwardVel - 32.0f) * 10.0f; | |||
} else { | |||
m->faceAngle[0] -= 0x400; | |||
} | |||
m->faceAngle[0] += m->angleVel[0]; | |||
if (m->faceAngle[0] > 0x2AAA) { | |||
m->faceAngle[0] = 0x2AAA; | |||
} | |||
if (m->faceAngle[0] < -0x2AAA) { | |||
m->faceAngle[0] = -0x2AAA; | |||
} | |||
m->vel[0] = m->forwardVel * coss(m->faceAngle[0]) * sins(m->faceAngle[1]); | |||
m->vel[1] = m->forwardVel * sins(m->faceAngle[0]); | |||
m->vel[2] = m->forwardVel * coss(m->faceAngle[0]) * coss(m->faceAngle[1]); | |||
m->slideVelX = m->vel[0]; | |||
m->slideVelZ = m->vel[2]; | |||
} | |||
</syntaxhighlight> | |||
Here are some tables summarizing the <code>approach_s32</code>, <code>update_flying_pitch</code>, and <code>update_flying_yaw</code> functions. | |||
{| class="wikitable" | |||
|+ | |||
update_flying_pitch (target vel = -(stickX * (forwardVel / 5))) | |||
! | |||
!joystick is down (move up) | |||
!joystick is up (move down) | |||
!joystick is neutral | |||
|- | |||
|negative pitch velocity | |||
|add 64 vel, cap at 32 | |||
| approach (at most 40 up or 20 down) | |||
|approach 0 (by at most 40) | |||
|- | |||
|positive pitch velocity | |||
| approach (at most 20 down or 40 up) | |||
|subtract 64 vel, cap at -32 | |||
|approach 0 (by at most 40) | |||
|- | |||
|zero pitch velocity | |||
| approach (at most 20 down or 40 up) | |||
| approach (at most 40 up or 20 down) | |||
| approach 0 (by at most 40) | |||
|} | |||
{| class="wikitable" | |||
|+update_flying_yaw (target vel = -(stickY * (forwardVel / 4))) | |||
! | |||
!joystick is left | |||
!joystick is right | |||
!joystick is neutral | |||
|- | |||
|negative yaw velocity | |||
| add 64 vel, cap at 16 | |||
|approach (at most 20 up or 10 down) | |||
|approach 0 (by at most 40) | |||
|- | |||
|positive yaw velocity | |||
| approach (at most 10 up or 20 down) | |||
| subtract 64 vel, cap at -16 | |||
|approach 0 (by at most 40) | |||
|- | |||
|zero yaw velocity | |||
|approach (at most 10 up or 20 down) | |||
|approach (at most 20 up or 10 down) | |||
|approach 0 (by at most 40) | |||
|} | |||
After that, update_flying_yaw does: | |||
#Add yaw velocity to yaw | |||
# Set roll to yaw times negative twenty (-20) | |||
'''Note that turning left = positive yaw''' (up = positive pitch).<ref>https://youtu.be/TQt8MCsniQI</ref> | |||
As can be seen, many joystick positions will be equivalent, and the pitch velocity or yaw velocity change by at most 40. | |||
* | |||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
/** | /** | ||
Line 133: | Line 224: | ||
m->angleVel[0] = approach_s32(m->angleVel[0], 0, 0x40, 0x40); | m->angleVel[0] = approach_s32(m->angleVel[0], 0, 0x40, 0x40); | ||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==References== | |||
<references /> | |||
{{Actions}} | {{Actions}} |
edits