Difference between revisions of "Flying"
Jump to navigation
Jump to search
m
removed unnecessary "heading normalization" bit; replaced 2d circle calculations w/ 3d sphere coordinate calculations for more accurate flying; adjusted heading clockwise based on directional controls
imported>8asrun6aer m |
imported>8asrun6aer m (removed unnecessary "heading normalization" bit; replaced 2d circle calculations w/ 3d sphere coordinate calculations for more accurate flying; adjusted heading clockwise based on directional controls) |
||
Line 46: | Line 46: | ||
float cstmYVelocity ; velocity towards y 0 point | float cstmYVelocity ; velocity towards y 0 point | ||
float cstmZVelocity ; velocity towards z 0 point | float cstmZVelocity ; velocity towards z 0 point | ||
float cstmPitch ; up/down angle player is facing | float cstmPitch ; up/down angle player is facing | ||
float cstmHeading ; 0-360 degrees from North player is facing | float cstmHeading ; 0-360 degrees from North player is facing | ||
Line 175: | Line 174: | ||
set cstmHeading to Player.GetAngle z | set cstmHeading to Player.GetAngle z | ||
set cstmPitch to ( Player.GetAngle x ) * -1 | set cstmPitch to ( Player.GetAngle x ) * -1 | ||
set cstmSpeed to 600 | |||
if ( isKeyPressed2 cstmControlForward ) | if ( isKeyPressed2 cstmControlForward ) | ||
; going forward | ; going forward | ||
; modify heading if strafing forward | |||
; modify heading if strafing | |||
if ( isKeyPressed2 cstmControlStrafeLeft ) | if ( isKeyPressed2 cstmControlStrafeLeft ) | ||
let cstmHeading += 320 | |||
elseif ( isKeyPressed2 cstmControlStrafeRight ) | elseif ( isKeyPressed2 cstmControlStrafeRight ) | ||
let cstmHeading += 45 | |||
endif | endif | ||
set cstmXVelocity to cos cstmPitch * sin cstmHeading * cstmSpeed | |||
set cstmYVelocity to cos cstmPitch * cos cstmHeading * cstmSpeed | |||
set cstmZVelocity to sin cstmPitch * cstmSpeed | |||
elseif ( isKeyPressed2 cstmControlBackward ) | elseif ( isKeyPressed2 cstmControlBackward ) | ||
; | ; going backward | ||
; modify heading if strafing backward | |||
; modify | |||
if ( isKeyPressed2 cstmControlStrafeLeft ) | if ( isKeyPressed2 cstmControlStrafeLeft ) | ||
let cstmHeading += 225 | |||
elseif ( isKeyPressed2 cstmControlStrafeRight ) | elseif ( isKeyPressed2 cstmControlStrafeRight ) | ||
let cstmHeading += 135 | |||
else | |||
let cstmHeading += 180 | |||
endif | endif | ||
set cstmXVelocity to cos cstmPitch * sin cstmHeading * cstmSpeed | |||
set cstmYVelocity to cos cstmPitch * cos cstmHeading * cstmSpeed | |||
set cstmZVelocity to sin cstmPitch * cstmSpeed * -1 | |||
else | else | ||
; modify in-place heading if strafing, otherwise hover in place | ; modify in-place heading if strafing, otherwise hover in place | ||
if ( isKeyPressed2 cstmControlStrafeLeft ) | if ( isKeyPressed2 cstmControlStrafeLeft ) | ||
let cstmHeading += 270 | |||
elseif ( isKeyPressed2 cstmControlStrafeRight ) | elseif ( isKeyPressed2 cstmControlStrafeRight ) | ||
let cstmHeading += 90 | |||
else | else | ||
set cstmSpeed to 0 ; just hovering in place | set cstmSpeed to 0 ; just hovering in place | ||
endif | endif | ||
set cstmXVelocity to sin cstmHeading * cstmSpeed | |||
set cstmYVelocity to cos cstmHeading * cstmSpeed | |||
set cstmZVelocity to ( ( GetLocalGravity z ) / ( 21 + ( 1 / 3 ) ) ) * cstmSecondsPassed | |||
endif | endif | ||
; player essentially "falls" to their new x,y,z coords | ; player essentially "falls" to their new x,y,z coords |