Jump to content

LUA script for displaying ship velocity on screen


IxionAlpha

Recommended Posts

Hi,

I am currently trying to display the ship velocity on one of my cockpit screens. It works just fine for a lot of stats like gravity or atmosphere density ant other. However, it does not work for the velocity and for the acceleration. What am I doing wrong?

 

Here the code:

local atmoDensity = (math.floor((unit.getAtmosphereDensity()*1000)))/1000 --export
local altitude = math.floor(core.getAltitude()) --export
local gForce = (math.floor((core.g()*1000)))/1000 --export
local shipVelocity = vec3(core.getVelocity()) --export
local shipAcceleration = vec3(core.getAcceleration()) --export
local pitch = (math.floor((gyro.getPitch()*1000)))/1000 --export
local yaw = (math.floor((gyro.getYaw()*1000)))/1000 --export
local roll = (math.floor((gyro.getRoll()*1000)))/1000 --export


html= [[
    <table style="
            margin-top = 10px;
            margin-left = auto;
            margin-right = auto;
            width: 80%;
            font-size: 3em;">
        <tr>
            <th>Atmosphere Density: </th>
            <th>Altitude</th>
            <th>g Force</th>
        </tr>
        <tr>
            <th>]] ..atmoDensity..[[</th>
            <th>]]..altitude..[[</th>
            <th>]]..gForce..[[</th>
        </tr>
    </table>
    
]]

leftScreen.setHTML(html)

html2= [[
        <table style="
            margin-top = 10px;
            margin-left = auto;
            margin-right = auto;
            width: 80%;
            font-size: 3em;">
        <tr>
            <th>Pitch: </th>
            <th>Yaw</th>
            <th>Roll</th>
        </tr>
        <tr>
            <th>]]..pitch..[[</th>
            <th>]]..yaw..[[</th>
            <th>]]..roll..[[</th>
        </tr>
        <tr>
            <th>Acceleration </th>
            <th>Velocity</th>
        </tr>
        <tr>
            <th>]]..shipAcceleration..[[</th>
            <th>]]..shipVelocity..[[</th>
        </tr>

    </table>
]]
frontScreen.setHTML(html2)

Link to comment
Share on other sites

  • 1 month later...
On 11/16/2020 at 8:27 AM, Musclethorpe said:

The warp calculator displays velocity on screen.

That's not what the OP is asking for.  Why do programmer-types never answer question posed but, instead, answer with their own question?  

Very odd subspecies of human...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...