Difference between revisions of "Flying"

Jump to navigation Jump to search
346 bytes removed ,  14:54, 31 December 2011
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 cstmZGravityModifyer ; counteracts effects of world gravity on Z
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
set cstmSpeed to 600
; modify heading if strafing forward
; modify heading if strafing
if ( isKeyPressed2 cstmControlStrafeLeft )
if ( isKeyPressed2 cstmControlStrafeLeft )
set cstmHeading to cstmHeading - 45
let cstmHeading += 320
elseif ( isKeyPressed2 cstmControlStrafeRight )
elseif ( isKeyPressed2 cstmControlStrafeRight )
set cstmHeading to cstmHeading + 45
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 )
; reverse speed
; going backward
set cstmSpeed to -600; allows acending backwards for easier combat targetting
; modify heading if strafing backward
; modify reverse heading if strafing
if ( isKeyPressed2 cstmControlStrafeLeft )
if ( isKeyPressed2 cstmControlStrafeLeft )
set cstmHeading to cstmHeading + 45
let cstmHeading += 225
elseif ( isKeyPressed2 cstmControlStrafeRight )
elseif ( isKeyPressed2 cstmControlStrafeRight )
set cstmHeading to cstmHeading - 45
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 )
set cstmSpeed to 600
let cstmHeading += 270
set cstmHeading to cstmHeading - 90
elseif ( isKeyPressed2 cstmControlStrafeRight )
elseif ( isKeyPressed2 cstmControlStrafeRight )
set cstmSpeed to 600
let cstmHeading += 90
set cstmHeading to 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
; normalize heading to 0-360 degree allowable range
if ( cstmHeading < 0 )
set cstmHeading to cstmHeading + 360
elseif ( cstmHeading > 360 )
set cstmHeading to cstmHeading - 360
endif
; use maths to adjust x,y direction of travel based on heading
set cstmXVelocity to sin cstmHeading * cstmSpeed
set cstmYVelocity to cos cstmHeading * cstmSpeed
; Set up/down velocity adjusting for gravity's influence and player's pitch
set cstmZGravityModifyer to ( ( GetLocalGravity z ) / ( 21 + ( 1 / 3 ) ) ) * cstmSecondsPassed ; see GetLocalGravity elderscrolls.com article for this formula
set cstmZVelocity to ( sin cstmPitch * cstmSpeed ) + cstmZGravityModifyer


; player essentially "falls" to their new x,y,z coords
; player essentially "falls" to their new x,y,z coords
Anonymous user

Navigation menu