Rinart73 Posted September 13, 2018 Share Posted September 13, 2018 0.18.3 Combining these two (as it suggested in Docs): local ship = Entity() ship:setToFlyToLocation(other.translationf) ship.desiredVelocity = 0 Results in infinitely spinning ship. I think it even exceeds yaw/pitch speed. Link to comment Share on other sites More sharing options...
Boxelware Team koonschi Posted September 14, 2018 Boxelware Team Share Posted September 14, 2018 Please post more details about how you're trying to use this function. Link to comment Share on other sites More sharing options...
Rinart73 Posted September 14, 2018 Author Share Posted September 14, 2018 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 More sharing options...
Boxelware Team koonschi Posted September 14, 2018 Boxelware Team Share Posted September 14, 2018 The flyToLocation order is a very low-level API function that you have to call every frame. Link to comment Share on other sites More sharing options...
Rinart73 Posted September 14, 2018 Author Share Posted September 14, 2018 Ok, I'll try. Still weird that it causes ship to spin, though. In theory, if I'll call it once, it just should perform part of the work and stop. Link to comment Share on other sites More sharing options...
Rinart73 Posted September 14, 2018 Author Share Posted September 14, 2018 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now