Author Topic: Player ship, and only player ship, refuses to accept scripted velocity change  (Read 404 times)

0 Members and 1 Guest are viewing this topic.

Player ship, and only player ship, refuses to accept scripted velocity change
Code: [Select]
#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

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.

 

Offline m!m

  • 210
Re: Player ship, and only player ship, refuses to accept scripted velocity change
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.

 
Re: Player ship, and only player ship, refuses to accept scripted velocity change
Yes, I've tried everything in $On Simulation: as well, with exactly the same effects.

 

Offline niffiwan

  • 211
  • Eluder Class
Re: Player ship, and only player ship, refuses to accept scripted velocity change
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)
Creating a fs2_open.log | Red Alert Bug = Hex Edit | MediaVPs 2014: Bigger HUD gauges | 32bit libs for 64bit Ubuntu
----
Linux OBS Packages: FSO 3.7.0 | FSO BP Build | wxLauncher (?) | PCS2 (?) | wxVPView (?)
Debian Packages (testing/unstable): Freespace2 | wxLauncher
----
m|m: I think I'm suffering from Stockholm syndrome. Bmpman is starting to make sense and it's actually written reasonably well...

  

Offline m!m

  • 210
Re: Player ship, and only player ship, refuses to accept scripted velocity change
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.