Alright so, after alot of time spent asking and slamming head towards the wall, all I got working is that my boat would eventually speed up and down in relation to where it was agaisnt the “wind direction”. No matter what I did, it would always go the way the wind was “blowing”.
What I want to achieve is this, (paint ftw):
What is happening here, is that the wind blows from south, the boat is turning north and the sail is turned agaisnt the wind coming from south, so that the boat is going at full speed towards north.
What has changed since last, is that the boat is now turning agaisnt west, but the sail is still turned agaisnt the wind that is coming from the south, meaning the boat will now go at full speed towards west.
This is just to demonstrate that if the sail is perpendicular with the wind, it will not catch any wind, and therefore the boat will not move.
My problem is, how would I achieve this? Will I have to make more than one entity or what?
function ENT:PhysicsSimulate( phys, deltatime )
if( nextsim < CurTime() ) then
nextsim = CurTime() + 0.02;
if( self.Entity:WaterLevel() == 0 ) then
if( nextthink < CurTime() ) then
nextthink = CurTime() + 1;
vector = GetGlobalVector( “WindVelocity” );
normal = vector:GetNormalized();
local phys = self.Entity:GetPhysicsObject()
if phys:IsValid() then
sail_normal = self.Entity:GetForward();
dot = normal:Dot( sail_normal );
phys:ApplyForceCenter( ( math.abs(dot) * ( mass * vector ) ) );
That’s my code for the sail entity as of yet, it kinda works, but I’ve explained what’s wrong earlier. That code may not be optimized or anything, but it is only for testing purposes.