• Wind Direction?
    4 replies, posted
Well, I'm making a sail that will act like a sail in real life would, my problem is, how would I check if my sail is turning agaisnt the wind direction? At the moment, I'm just generating a random vector, multiplying it by the models mass, and then phys.ApplyForceCenter. It works great, except, that the boat will keep spinning around. Code that I use to apply the force: [lua] function ENT:Think() if( nextthink < CurTime() ) then nextthink = CurTime() + 1; vector = GetGlobalVector( "WindVelocity" ); end if( self.Entity:WaterLevel() == 0 ) then local phys = self.Entity:GetPhysicsObject() if phys:IsValid() then phys:ApplyForceCenter( ( mass * vector ) ); print( "Min: " .. tostring( mass * vector ) ); end end end [/lua] and creating the vector is just this: [lua] SetGlobalVector( "WindVelocity", Vector( math.random( -10, 10 ), math.random( -10, 10 ), 0 ) ); [/lua] Any help appreciated.
There is no "Wind direction" in the game so you'll have to set your own.
Uh, that was what I meant? :O I need some help with checking if my sail entity is turning agaisnt the direction from where the wind is. That's the only thing I need some help with.
You'd do it with some simple vector math.. [lua] local wind_normal = GetGlobalVector( "WindVelocity" ):GetNormal( ); local sail_normal = entity:GetForward( ); local dot = wind_normal:Dot( sail_normal ); [/lua] Dot would be 1 if the wind normal is pointing in the same direction as sail normal, 0 if they are perpendicular and -1 if pointing the opposite direction.
Thanks alot for that Nevec!
Sorry, you need to Log In to post a reply to this thread.