Hello there. Just something small I need help on. I made two different float functions which calculate the force needed to push a boat upwards. I am not happy about what it looks like.
for example I am currently using this (VerticalSpeed / abs(VerticalSpeed))
to get a unit direction of the vertical speed. I feel this is not good enough. Is there a better way?
The code works fine. This is the outcome. https://gyazo.com/df943a85b01ab375816faea0081d9dc0 Does anyone have any ideas to improve this?
function SeaPhysics:GetDifferenceForce(CurrentPosition,VerticalSpeed,PartMass)
-- Looks messy. I might have to refactor this later
EastWestHeight = sin(rad((CurrentPosition.X*self.WaveSize + self.Time)))
NorthSouthHeight = sin(rad((CurrentPosition.Z*self.WaveSize + self.Time)))
ElevationTarget = (EastWestHeight+NorthSouthHeight)*self.WaveHeight
DragForce = (VerticalSpeed == 0 and 0) or (VerticalSpeed) * abs(VerticalSpeed) * (VerticalSpeed / abs(VerticalSpeed)) * -DRAG_FORCE_COEFFICIENT -- Strange
ElevationDifference = ElevationTarget - CurrentPosition.Y
ResultingForce = (ElevationDifference * self.P) + DragForce -- Better way to get this?
return ResultingForce
end
function SeaPhysics:CalculateBuoyancyForce(CurrentPosition,VerticalSpeed,UnitDisplacement)
-- Looks messy. I might have to refactor this later
EastWestHeight = sin(rad((CurrentPosition.X*self.WaveSize + self.Time)))
NorthSouthHeight = sin(rad((CurrentPosition.Z*self.WaveSize + self.Time)))
ElevationTarget = (EastWestHeight+NorthSouthHeight)*self.WaveHeight
ElevationDifference = ElevationTarget - CurrentPosition.Y
DragForce = (VerticalSpeed == 0 and 0) or abs(VerticalSpeed) * abs(VerticalSpeed) * (VerticalSpeed / abs(VerticalSpeed))-- * -self.D -- EEEWWW
DisplacedVolume = ElevationDifference > 0 and ElevationDifference * UnitDisplacement or 0 -- OH DEAR
ResultingForce = (DisplacedVolume * GRAVITY * WATER_DENSITY) + DragForce -- I AM HAVING A BRAIN SEIZURE too much maths
return ResultingForce
end