Difference between revisions of "Script - Corridor Mode"
From FreeSpace Wiki
m (header + link) |
AndrewofDoom (talk | contribs) (Someone forgot to change this. The createCamera and setCamera calls are no longer a part of the testing library, but the graphics one. I have updated it accordingly.) |
||
Line 31: | Line 31: | ||
---Create chase camera | ---Create chase camera | ||
− | objectCCamera = | + | objectCCamera = gr.createCamera("Chase Camera",vectorCCameraPos, orientationCCamera) |
---Use the new chase camera | ---Use the new chase camera | ||
− | + | gr.setCamera(objectCCamera) | |
---Create front vector | ---Create front vector |
Latest revision as of 18:21, 19 June 2012
Uses modular version of the scripting.tbl, xxx-sct.tbm. Script enables a simple tube flying mode for the game.
Table Entry
tube-sct.tbm
#Conditional Hooks $State: GS_STATE_GAME_PLAY $On Frame: [ floatMissionTime = mn.getMissionTime() if floatMissionTime ~= nil then if booleanCorridorInit == nil and floatMissionTime < 0.5 then --Setup all the needed values booleanCorridorInit = "true" ---Create 'blank' orientation orientationBlank = mn.Ships[1].Orientation orientationBlank["p"] = 0 orientationBlank["b"] = 0 orientationBlank["h"] = 0 ---Set the initial camera position and orientation vectorCCameraPos = ba.createVector(0,15,-75) orientationCCamera = orientationBlank ---Create chase camera objectCCamera = gr.createCamera("Chase Camera",vectorCCameraPos, orientationCCamera) ---Use the new chase camera gr.setCamera(objectCCamera) ---Create front vector vectorFrontDirection = ba.createVector(0,0,100) --- objectAimingAid1 = mn.Ships["AimingAid I"] objectAimingAid2 = mn.Ships["AimingAid II"] objectAimingAid3 = mn.Ships["AimingAid III"] ---Set movement box limits floatHLimit = 30 floatVLimit = 22.5 end if floatMissionTime > 0.5 then if booleanCorridorInit ~= nil then booleanCorridorInit = nil end objectPlayer = hv.Player if objectPlayer:isValid() then --Player Validity Check --Make sure that we needed info if orientationLast == nil then orientationLast = objectPlayer.Orientation end --Get Position and Orientation and Speed orientationCurrent = objectPlayer.Orientation vectorCurrentPos = objectPlayer.Position floatPlayerSpeed = objectPlayer.Physics:getSpeed() vectorPlayerVelocity = objectPlayer.Physics.Velocity --Set the 3D aiming aid system ---Get Aiming Aids ---Get players 'nose vector' vectorPointer = orientationCurrent:unrotateVector(vectorFrontDirection) --Set chase camera position according to the ships position vectorCCameraPos["y"] = vectorCCameraPos["y"] - ((vectorCCameraPos["y"] -15) - vectorCurrentPos["y"]) / 150 vectorCCameraPos["x"] = vectorCCameraPos["x"] - (vectorCCameraPos["x"] - vectorCurrentPos["x"]) / 150 vectorCCameraPos["z"] = vectorCurrentPos["z"] - 50 - 0.2 * floatPlayerSpeed --Set chase camera orientation according to ship position ---Create vector components floatCCameraOriVec_y = -((vectorCCameraPos["y"] - 15) - vectorCurrentPos["y"])/3 floatCCameraOriVec_x = -(vectorCCameraPos["x"] - vectorCurrentPos["x"])/3 floatCCameraOriVec_z = 50 + 0.2 * floatPlayerSpeed ---Create vector from the vector components vectorCCameraNewOri = ba.createVector(floatCCameraOriVec_x,floatCCameraOriVec_y,floatCCameraOriVec_z) ---Create orientation object from the vector object orientationCCameraNew = vectorCCameraNewOri:getOrientation() --Update chase camera position and orientation objectCCamera:setPosition(vectorCCameraPos) objectCCamera:setOrientation(orientationCCameraNew) --Get current rotational velocity data vectorRealRotVel = objectPlayer.Physics.RotationalVelocity --Set limit for turning for horizontal axis if math.pow(orientationCurrent["h"],2) > math.pow(orientationLast["h"],2) then vectorRealRotVel[2] = vectorRealRotVel[2] - 1*(orientationCurrent["h"])/3 else vectorRealRotVel[2] = vectorRealRotVel[2] - 1*(orientationCurrent["h"])/5 end --Set limit for turning for vertical axis if math.pow(orientationCurrent["p"],2) > math.pow(orientationLast["p"],2) then vectorRealRotVel[1] = vectorRealRotVel[1] - 1*(orientationCurrent["p"])/3 else vectorRealRotVel[1] = vectorRealRotVel[1] - 1*(orientationCurrent["p"])/5 end --Prevent rolling floatCurrentRoll = orientationCurrent["b"] if floatCurrentRoll ~= 0 then vectorRealRotVel[3] = -2*floatCurrentRoll/2 end --Horizontal Position Limit if objectPlayer.Position["x"] > floatHLimit then vectorPlayerVelocity["x"] = vectorPlayerVelocity["x"] - (vectorCurrentPos["x"] - floatHLimit) vectorPointer["x"] = vectorPointer["x"] + (vectorCurrentPos["x"] - floatHLimit) elseif vectorCurrentPos["x"] < (-1 * floatHLimit) then vectorPlayerVelocity["x"] = vectorPlayerVelocity["x"] - (vectorCurrentPos["x"] + floatHLimit) vectorPointer["x"] = vectorPointer["x"] + (vectorCurrentPos["x"] + floatHLimit) end --Vertical Position Limit if objectPlayer.Position["y"] > floatVLimit then vectorPlayerVelocity["y"] = vectorPlayerVelocity["y"] - (vectorCurrentPos["y"] - floatVLimit) vectorPointer["y"] = vectorPointer["y"] + (vectorCurrentPos["y"] - floatVLimit) elseif vectorCurrentPos["y"] < (-1 * floatVLimit) then vectorPlayerVelocity["y"] = vectorPlayerVelocity["y"] - (vectorCurrentPos["y"] + floatVLimit) vectorPointer["y"] = vectorPointer["y"] + (vectorCurrentPos["y"] + floatVLimit) end ---Set 3D aiming aid positions vectorNewTargetPos = vectorCurrentPos + vectorPointer/(1/1.25) objectAimingAid1.Position = vectorNewTargetPos vectorNewTargetPos = vectorCurrentPos + vectorPointer/(1/2.5) objectAimingAid2.Position = vectorNewTargetPos vectorNewTargetPos = vectorCurrentPos + vectorPointer/(1/5) objectAimingAid3.Position = vectorNewTargetPos --Update Player Rotational Velocity, Position and Orientation objectPlayer.Physics.RotationalVelocity = vectorRealRotVel objectPlayer.Physics.Velocity = vectorPlayerVelocity --Reference Orientation for next frame orientationLast = objectPlayer.Orientation --new section to remove excess enemy fighters and bombers integerShips = #mn.Ships --Get rid off excess enemies for g=1,integerShips do objectDisposableShip = mn.Ships[g] --Check team and hitpoint status stringDisposableShipTeam = objectDisposableShip.Team.Name floatDisposableShipHitpoints = objectDisposableShip.HitpointsLeft if stringDisposableShipTeam ~= "Friendly" and floatDisposableShipHitpoints > 0 then --Only fighters & bombers stringDisposableShipType = objectDisposableShip.Class.Type.Name if stringDisposableShipType == "Fighter" or stringDisposableShipType == "Bomber" then --Move ship only if it has flown past the player vectorDisposableShipPosition = objectDisposableShip.Position floatFrontDistance = vectorDisposableShipPosition["z"] - vectorCurrentPos["z"] if floatFrontDistance < -100 then vectorDispose = ba.createVector(0,0,-50000) --Update the moved ships position and get rid off it objectDisposableShip.Position = vectorDispose objectDisposableShip.HitpointsLeft = 0 objectDisposableShip:kill(objectDisposableShip) end end end end end --Player Validity Check end end ] #End
Notes
Script avoids directly changing the position data of the player ship to avoid several potential physics problems. Handles 3D targeting controls should proper models be included to the mission. Script also removes all hostile fighters and bombers that have passed the player ship and kills them. Radar-set-max-range SEXP should be used to prevent the targeting of the disposed ships.