Modding, Mission Design, and Coding > The Scripting Workshop

Player ship, and only player ship, refuses to accept scripted velocity change

(1/1)

xenocartographer:

--- Code: ---#Conditional Hooks
$Application: FS2_Open

$State: GS_STATE_GAME_PLAY
$On Frame: [
local numShips = #mn.Ships
for i=1, numShips do
local ship = mn.Ships[i]
if ship.Class.Name == "GTF Ulysses" then
local vel = ship.Orientation:getFvec() * 500
ship.Physics.Velocity = vel
ship.Physics.VelocityDesired = vel
end
end
]


#End

--- End code ---

With Alpha wing (three Ulysses) in the mission, along with a cargo container as a reference point, Alpha 2 and 3 show the expected behavior and become stupid fast (and, typically, die hilariously by crashing into things), while Alpha 1... is completely unaffected. I want to know why, and more importantly, how to fix it.

For added fun, removing ship.Physics.Velocity = vel means the ships still have absurd velocity, but it tends to float around 523 m/s (with no scripted bull****, they'd be traveling at 23 m/s, so it looks additive?), while removing leaving that line and removing ship.Physics.VelocityDesired = vel seems to leave the script completely impotent. Setting local vel = ba.createVector(0, 0, 500) causes Alpha 1 to fly off in the global (0, 0, 1) direction whenever I turn, which is particularly confusing.

Obviously, my actual use case is something that makes a little bit more sense than the above.

m!m:
Have you tried using the On Simulation hook? It should be the best place for altering the physics of the game since it runs just after the usual physics code which means you can overwrite the values written by that code without causing too many issues.

xenocartographer:
Yes, I've tried everything in $On Simulation: as well, with exactly the same effects.

niffiwan:
I'm hardly an expert on this, but I think the players controls are wired into the players input from mouse/keyboard/etc. Have you tried setting the player ship to be under AI control? Alternatively, perhaps try overriding the players input completely, I think there's a hook/setting that lets you do this? (sorry, I've only messed with this section of the code peripherally)

m!m:
I have looked through the code a bit and it looks like niffiwan is correct. If you put the player under AI control then the player controls will not overwrite the values set by Lua.

Navigation

[0] Message Index

Go to full version