# Programming boat sails to turn according to wind direction

I am trying to make a sailboat driven by the player with sails that turn as the boat moves according to the wind direction.
I have used Boat Controller by NSdesign Games and got a very effective system to drive a Yacht I modeled in C4D.
However my original plan to use Physics to make the sails turn has gone west because adding any physics colliders to the boat or its sail or boom mess up the Boat Controller floatation bit and the boat sinks. I don’t think I can alter this in Boat Controller.

So, I am wondering how to go about a simple script that would turn the sail and boom on the boat within a limited amount so that the sail is always angled a little away from the wind direction like a real sail would, no matter how the boat is steered the sails turn to align with the wind direction.

I have not found a script example yet that used a constant direction to turn from, only fixed co ordinates, and am wondering if anyone has any ideas how to go about this.

There’s a wheel to turn too, but I think that should be straightforward, its the turning according to a specific world direction thing I am stuck on so far.

Thank you.

This is a pretty open ended questions in the absence of some code, but I think Quaternion.LookRotation() will do the job for you. Given that you’ve calculated the direction you want to point the boat, you can do this in an Update() loop:

`````` transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(dir), speed * Time.deltaTime);
``````

‘speed’ is a variable you create and assign and is measured in degrees per second. ‘dir’ the direction you want the boat to face. If you’d like a more eased rotation, you can replace ‘RotateTowards’ with ‘Slerp’ and greatly reduce the value of ‘speed’. I cannot tell from this question if any of the Physics engine is being used. If Physics is being used, consider using Physics.MoveRotation() rather than directly assigning the rotation as I’ve done in this line of code.

when you sail a boat, you don’t let the sails go where the wind pushes them. Keeping them tight against the wind is actually what gets you your best speed.

Unless its a spinnaker, a sail ISNT a parachute… its a wing.