Difference between revisions of "Flying"
Jump to navigation
Jump to search
m
replacing ascension/descension formulas with better math, and getting rid of speed penalties for diving vs rising to present just a very basic flight script
imported>8asrun6aer m (→Notes) |
imported>8asrun6aer m (replacing ascension/descension formulas with better math, and getting rid of speed penalties for diving vs rising to present just a very basic flight script) |
||
Line 2: | Line 2: | ||
Flying isn't normally something players can do. Here's a script to allow that. | Flying isn't normally something players can do. Here's a script to allow that. | ||
This isn't so much of a snippet of code as it is the complete code for allowing a player to fly in a more or less natural way. The script below uses velocity functions that prevent wall, ceiling, floor, and obstacle clipping. Setting up when and how to allow the player to fly ( via casted spell or constant ability) is up to you - the modder. But for this article, we'll be setting up a new constant Player Ability which will allow the player to initiate flying at any time by pressing a key. | This isn't so much of a snippet of code as it is the complete code for allowing a player to fly in a more or less natural way. The script below uses velocity functions that prevent wall, ceiling, floor, and obstacle clipping. Setting up when and how to allow the player to fly (via casted spell or constant ability) is up to you - the modder. But for this article, we'll be setting up a new constant Player Ability which will allow the player to initiate flying at any time by pressing a key. | ||
Not only can you grant the ability to fly to users of your mod with such a script, but you can use this script yourself as a modder to test every inch of your newly modded world space in a live environment. | Not only can you grant the ability to fly to users of your mod with such a script, but you can use this script yourself as a modder to test every inch of your newly modded world space in a live environment. | ||
Line 17: | Line 17: | ||
This script assigns the "/" key to begin and end flying mode. You can change this at or around line 62 in this script where it assigns this key value to the 'cstmControlActivateFlyMode' variable (for a list of valid keyboard key ID's to use instead, see [[GetControl]]). | This script assigns the "/" key to begin and end flying mode. You can change this at or around line 62 in this script where it assigns this key value to the 'cstmControlActivateFlyMode' variable (for a list of valid keyboard key ID's to use instead, see [[GetControl]]). | ||
While flying, use the regular forward/backward/strafe keys for movement. Should the player ever reassign directional control keys, flight controls will be reset only after the player reloads the game. This directional control reassignment on game-load happens around line | While flying, use the regular forward/backward/strafe keys for movement. Should the player ever reassign directional control keys, flight controls will be reset only after the player reloads the game. This directional control reassignment on game-load happens around line 56. | ||
Use the mouse to control flight direction/heading. | Use the mouse to control flight direction/heading. While facing in a downward angle and moving backwards, the player will ascend as this effect should help players with keeping track of combat targets on the ground. | ||
Line 27: | Line 27: | ||
Also, note the only code block used by this example magic effect script is the [[ScriptEffectUpdate]] block. The [[ScriptEffectFinish]] block is irrelevant to constant abilities, and the [[ScriptEffectStart]] block would make this script too dependent on initial new game environments. Though if made part of a regular duration spell effect, you could use [[ScriptEffectStart]] for set up, and [[ScriptEffectFinish]] for cleanup. | Also, note the only code block used by this example magic effect script is the [[ScriptEffectUpdate]] block. The [[ScriptEffectFinish]] block is irrelevant to constant abilities, and the [[ScriptEffectStart]] block would make this script too dependent on initial new game environments. Though if made part of a regular duration spell effect, you could use [[ScriptEffectStart]] for set up, and [[ScriptEffectFinish]] for cleanup. | ||
To easily distinguish local variables for the sake of readability in this example script, each | To easily distinguish local variables for the sake of readability in this example script, each local variable name begins with 'cstm'. Also, the script is heavily commented to hopefully make each step more clear. | ||
<pre> | <pre> | ||
scn cstmFlightScript | scn cstmFlightScript | ||
; ************* | ; ************* | ||
Line 47: | Line 48: | ||
float cstmZGravityModifyer ; counteracts effects of world gravity on Z | 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 | ||
float cstmSpeed ; updated rate of player movement in any given direction | float cstmSpeed ; updated rate of player movement in any given direction | ||
Line 85: | Line 84: | ||
;******************************* | ;******************************* | ||
; Reset | ; Reset Key bindings on game load | ||
;******************************* | ;******************************* | ||
if ( GetGameRestarted || GetGameLoaded ) | if ( GetGameRestarted || GetGameLoaded ) | ||
Line 138: | Line 137: | ||
</pre> | </pre> | ||
Pausing here for a second. This script damages the player's fatigue while flying to avoid encouraging the player to fly over every dangerous situation in the game. You may also | Pausing here for a second. This script damages the player's fatigue while flying to avoid encouraging the player to fly over every dangerous situation in the game. You may also replace this to damage magika instead if you like. If you're only testing a new map you've just made, or if you're making this script part of a regular short-duration spell, you'll want to comment out or delete this section of the script as it'll only be an inconvenience. Otherwise, think twice about letting the player fly around without a care in the world. | ||
<pre> | <pre> | ||
Line 171: | Line 170: | ||
<pre> | <pre> | ||
;******************************* | ;******************************* | ||
; Movement | ; Movement | ||
;******************************* | ;******************************* | ||
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 | |||
if ( isKeyPressed2 cstmControlForward ) | if ( isKeyPressed2 cstmControlForward ) | ||
; going forward | ; going forward | ||
set cstmSpeed to | set cstmSpeed to 600 | ||
; modify heading if strafing | ; modify heading if strafing | ||
if ( isKeyPressed2 cstmControlStrafeLeft ) | if ( isKeyPressed2 cstmControlStrafeLeft ) | ||
Line 196: | Line 187: | ||
elseif ( isKeyPressed2 cstmControlBackward ) | elseif ( isKeyPressed2 cstmControlBackward ) | ||
; reverse speed | ; reverse speed | ||
set cstmSpeed to | set cstmSpeed to -600; allows acending backwards for easier combat targetting | ||
; modify reverse heading if strafing | ; modify reverse heading if strafing | ||
if ( isKeyPressed2 cstmControlStrafeLeft ) | if ( isKeyPressed2 cstmControlStrafeLeft ) | ||
Line 211: | Line 197: | ||
; 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 | set cstmSpeed to 600 | ||
set cstmHeading to cstmHeading - 90 | set cstmHeading to cstmHeading - 90 | ||
elseif ( isKeyPressed2 cstmControlStrafeRight ) | elseif ( isKeyPressed2 cstmControlStrafeRight ) | ||
set cstmSpeed to | set cstmSpeed to 600 | ||
set cstmHeading to cstmHeading + 90 | set cstmHeading to cstmHeading + 90 | ||
else | else | ||
Line 233: | Line 219: | ||
; Set up/down velocity adjusting for gravity's influence and player's pitch | ; Set up/down velocity adjusting for gravity's influence and player's pitch | ||
set cstmZGravityModifyer to ( ( GetLocalGravity z ) / ( 21 + ( 1 / 3 ) ) ) * cstmSecondsPassed | set cstmZGravityModifyer to ( ( GetLocalGravity z ) / ( 21 + ( 1 / 3 ) ) ) * cstmSecondsPassed ; see GetLocalGravity elderscrolls.com article for this formula | ||
set cstmZVelocity to ( | 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 | ||
Line 253: | Line 239: | ||
# A player can fly over castle walls in exterior world spaces. Because they didn't enter the castle grounds through the front door, they'll be bewildered by how every building within the castle walls is nothing but a fake graphics placeholder. There are "Open Cities" mods out there that should correct that. | # A player can fly over castle walls in exterior world spaces. Because they didn't enter the castle grounds through the front door, they'll be bewildered by how every building within the castle walls is nothing but a fake graphics placeholder. There are "Open Cities" mods out there that should correct that. | ||
# Though modified heavily from the original code and using different procedural flow with new methods and solutions for flying controls and effects, some of the basic flight concepts of the above script were based on the flying script packaged with the "A Chingari and Ismelda Demon Race:Demon Race v3-0-3" mod found at the [[TESNexus]] site. (Note that the mod contains adult content, and cannot be linked to from this site. If you choose to find it by searching TES Nexus, you accept that you may be subject to said adult content.) | # Though modified heavily from the original code and using different procedural flow with new methods and solutions for flying controls and effects, some of the basic flight concepts of the above script were based on the flying script packaged with the "A Chingari and Ismelda Demon Race:Demon Race v3-0-3" mod found at the [[TESNexus]] site. (Note that the mod contains adult content, and cannot be linked to from this site. If you choose to find it by searching TES Nexus, you accept that you may be subject to said adult content.) | ||
# For bugs, better equations, etc, see the [[Talk:Flying|Discussion] page on this topic. | |||
[[Category: Useful Code]] | [[Category: Useful Code]] |