Quantcast
Channel: Questions in topic: "web player"
Viewing all articles
Browse latest Browse all 531

Boat rotating(rolling) on x and z axis based on height of water at front,back,left right

$
0
0
I'm currently trying to improve a floating script to enable a boat to roll on waves. In it's initial state the boat only moves based on the height of the water at it's position. To improve this I am trying to rotate the boat on X and Z based on the height of the water at the front, back , left and right. I'm sure this involves some application of trig however I am not familiar enough with how to apply this. In addition the rotation at 2 angles at once may complicate it further. void FixedUpdate() { //Original script: Currently determines height of boat if ( Water == null ) return; height = Water.GetHeightAtPoint( transform.position ); transform.position = new Vector3( transform.position.x, height, transform.position.z ); // //New code to make boat roll with waves. //Position height of water will be determined from shipPosFront = new Vector3(transform.position.x, transform.position.y, transform.position.z + shipSizeZ); shipPosBack = new Vector3(transform.position.x, transform.position.y, transform.position.z - shipSizeZ); shipPosRight = new Vector3(transform.position.x + shipSizeX, transform.position.y, transform.position.z); shipPosLeft = new Vector3(transform.position.x - shipSizeX, transform.position.y, transform.position.z); shipHeightFront = Water.GetHeightAtPoint(shipPosFront); shipHeightBack = Water.GetHeightAtPoint(shipPosBack); shipHeightRight = Water.GetHeightAtPoint(shipPosRight); shipHeightLeft = Water.GetHeightAtPoint(shipPosLeft); //How do we convert these 4 heights to x/z rotation? } The basic floating script came with the Hydroform asset on the Unity store.

Viewing all articles
Browse latest Browse all 531

Trending Articles