Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use tweening. A wonderful technique to change values smoothly be-<em>tween</em> two values. In this case you can tween from your awkward bouncing angles to your boats sitting rotation by tweening between the two. There are good plugins to use like <a href="http://itween.pixelplacement.com/" rel="nofollow">iTween</a> which is fantastic but I will show you some half pseudo - half super-cereal code to get you started on the concept for "rotation correction"</p> <p>Lets say I have my boat hit a nice big wave and its pointing my boat upwards to a 20deg angle.</p> <p>My euler angle on X is 20 and I can return this to 0 by increasing the decreasing the value at a constant rate. I'm just showing X here but you can repeat the process for Z-axis. I would exclude Y as you will use your direction of your boat on Y and you don't want to screw up your boats navigation.</p> <pre><code>Update() float angleDelta; // check if value not 0 and tease the rotation towards it using angleDelta if(transform.rotation.X &gt; 0 ){ angleDelta = -0.2f; } elseif (transform.rotation.X &lt; 0){ angleDelta = 0.2f; } transform.rotation.X += angleDelta; } </code></pre> <p>This incredibly simple implementation does the job but has the wonderful perk of being incredibly "snappy" and "jittery". So we want to add some smoothing to make it a more <em>lifelike</em> boat.</p> <p>We do this by adding in a variable to the angleDelta:</p> <pre><code>Vector3 previousAngle; float accelerationBuffer = 0.3f; float decelerationBuffer = 0.1f; Update() Vector3 angleDelta; //assuming that x=0 is our resting rotation if(previousAngle.X &gt; transform.rotation.X &amp;&amp; transform.rotation.X &gt; 0){ //speed up rotation correction - like gravity acting on boat angleDelta.X += (previousAngle.X - transform.rotation.X) * accelerationBuffer; } elseif(previousAngle.X &lt; transform.rotation.X &amp;&amp; transform.rotation.X &gt; 0 //angle returning to resting place: slow down the rotation due to water resistatnce angleDelta.X -= (previousAngle.X - transform.rotation.X) * deccelerationBuffer; } //If boat pointing to sky - reduce X if(transform.rotation.X &gt; 0 ){ transform.rotation.X -= angleDelta.X * Time.deltaTime; //If boat diving into ocean - increase X } elseif (transform.rotation.X &lt; 0){ transform.rotation.X += angleDelta.X * Time.deltaTime; //Must not forget to use deltaTime! } //record rotation for next update previousAngle = transform.rotation; } </code></pre> <p>This is an incredibly rough draft but it gets across the theory that I'm trying to explain - you will need to adjust your own code accordingly as you haven't included any of your own (pastebin a snippet to us and maybe we can elaborate more!)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload