Rinart73 Posted August 14, 2018 Share Posted August 14, 2018 I need to rotate one ship so it would face another. I need to do this gradually and fairly (so it would not exceed ship's yaw and pitch). I thought that "Velocity():addRotation(vec3 axis, float angle)" or "Velocity():setAngularVelocity(vec3 axis, float angle)" could help me with this. Currently my code looks like this. function MyMod.doServer(self, other) -- finding where we need to look to look directly at other ship local lookOther = normalize(other.translationf - self.translationf) -- vector that is perpendicular to the both should be an axis local axis = cross(lookOther, self.look) -- angle in radians local angle = -atan2(length(axis), dot(lookOther, self.look)) Velocity():addRotation(axis, angle) broadcastInvokeClientFunction("rotateOnClient", axis, angle) end function MyMod.rotateOnClient(axis, angle) Velocity():addRotation(axis, angle) end I have no problems with axis, I think. Ship rotates in the correct direction. But it's either rotates too much or not enough. Apparently there is something wrong with the "addRotation" function. Because if we'll multiply axis vector by 50 for example ship will spin like crazy. Why? It's an axis, it affects direction of rotation, not the rotation 'power'. We have an angle argument for that. I really need help with this guys :( 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