Jump to content

Welcome to the Forum!

The best place to exchange builds and ideas! Vote for the best ideas and suggestions here.

Join the Avorion Discord!

Connect with other passionate players and talk about the latest news.
Discord

DLC Avorion Into the Rift Out Now!

Now available on Steam!
Steam

0.18.3 - Entity():setToFlyToLocation - infinite spinning


Rinart73
 Share

Recommended Posts

local abs = math.abs

local isRotating = false

function MyMod.getUpdateInterval()
    return 1
end

function MyMod.updateServer(timeStep)
    local ship = Entity()
    local target = myFunctionGetTarget() -- I checked, it's an entity

    -- I need ship to face target, so I check difference between where ship looks and where it needs to look
    local look = ship.look
    local lookOther = normalize(target.translationf - ship.translationf)
    local difference = lookOther - look
    difference = abs(difference.x) + abs(difference.y) + abs(difference.z)

    if difference > 0.5 and not isRotating then
        ship:setToFlyToLocation(target.translationf)
        ship.desiredVelocity = 0
        isRotating = true
    elseif isRotating then
        isRotating = false
    end
end

 

As you see from the code above, I call "setToFlyToLocation" function only once. I thought that the ship will just rotate in place and when it will face target entity I will start to do next part of code.

Link to comment
Share on other sites

Now when I'm using this function every frame, ship seems to rotate correctly, but there is no way to stop it. So it reaches correct direction, script stops calling "setToFlyToLocation", but ship (as in the first message) continues to rotate with increasing speed.

I tried all of these, nothing can stop ship from rotating:

ship:setToFlyToLocation(ship.translationf)
ShipAI():setIdle()
ShipAI():setPassive()
Velocity():setAngularVelocity(ship.look, 0)

 

local abs = math.abs

local isRotating = false

function MyMod.getUpdateInterval()
    if not isRotating  then return 1 end
end

function MyMod.updateServer(timeStep)
    local ship = Entity()
    local target = myFunctionGetTarget() -- I checked, it's an entity

    -- I need ship to face target, so I check difference between where ship looks and where it needs to look
    local look = ship.look
    local lookOther = normalize(target.translationf - ship.translationf)
    local difference = lookOther - look
    difference = abs(difference.x) + abs(difference.y) + abs(difference.z)

    if difference > 0.5 then
        ship:setToFlyToLocation(target.translationf)
        ship.desiredVelocity = 0
        isRotating = true
    elseif isRotating then
        isRotating = false
    end
end

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
 Share

×
×
  • Create New...