- Home /
Floating object on the water and stand on it.
Hi, I have a problem about floating object on the water.
Video: Example
I want stand on the ice and jump to next ice, but....ice is crazy rotation..how can I fix that?
My script(& I use mesh collider on the ice,is it right?):
 using UnityEngine;
 using System.Collections;
  
 public class floatWater : MonoBehaviour {
  
     public float offset = 1.5f;
     public float speed = 0.8f;
     private Vector3 startPos;
  
     void Start() {
        startPos = transform.position;    
     }
  
     void Update() {
        transform.position = startPos + Vector3.up * Mathf.Sin (Time.time * speed);   
     }
 }
Thanks a lots for the help :(
Answer by jonnyhopper · Oct 24, 2013 at 08:18 PM
Hi!
In the rigidBody for the ice you can set Freeze Rotation for each axis in the Constraints section. Would that do what you need?
Jonny.
hey, thanks for the answer (:
Ice won't rotation now!! and I figure out why not my character cannot stand on it!
Thanks!!!
- Check that the ice has a Collider on it (and it's the right size). 
- Also check the Collision $$anonymous$$atrix in Edit/Project Settings/Physics matches so that the layer the ice is set on and the character's layer are set to collide. 
Hi, thanks for the answer continuously (:
I have find some script include boat movement and floating, but it was flipping down, do you know how can I fix this? (It can't freeze rotation, or it will be can't control)
$$anonymous$$y example video
This is my code:
     var hoverHeight : float = 3;
     var hoverHeightStrictness : float = 1.0;
     var  forwardThrust : float = 5000.0;
     var  backwardThrust : float = 2500.0;
     var  bankAmount : float = 0.1;
     var  bankSpeed : float = 0.2;
     var  bankAxis : Vector3 = new Vector3(-1.0, 0.0, 0.0);
     var  turnSpeed : float = 8000.0;
  
     var  forwardDirection : Vector3 = new Vector3(0.0, 0.0, 1.0);
  
     var  mass : float = 5.0;
  
     // positional drag
     var sqrdSpeedThresholdForDrag : float = 25.0;
     var superDrag : float = 2.0;
     var fastDrag : float = 0.5;
     var slowDrag : float = 0.01;
  
     // angular drag
     var sqrdAngularSpeedThresholdForDrag : float = 5.0;
     var superADrag : float = 32.0;
     var fastADrag : float = 16.0;
     var slowADrag : float = 0.1;
  
  
  
     var playerControl : boolean = true;
  
     private var bank : float = 0.0;
  
     function SetPlayerControl(control : boolean)
     {
         playerControl = control;
     }
  
  
     function Start()
     {
         gameObject.rigidbody.mass = mass;
     }
  
     function FixedUpdate()
     {
         if ($$anonymous$$athf.Abs(thrust) > 0.01)
         {
             if (rigidbody.velocity.sqr$$anonymous$$agnitude > sqrdSpeedThresholdForDrag)
                 rigidbody.drag = fastDrag;
             else
                 rigidbody.drag = slowDrag;
         }
         else
             rigidbody.drag = superDrag;
  
         if ($$anonymous$$athf.Abs(turn) > 0.01)
         {
             if (rigidbody.angularVelocity.sqr$$anonymous$$agnitude > sqrdAngularSpeedThresholdForDrag)
                 rigidbody.angularDrag = fastADrag;
             else
                 rigidbody.angularDrag = slowADrag;
         }
         else
             rigidbody.angularDrag = superADrag;
  
         transform.position = Vector3.Lerp(transform.position, new Vector3(transform.position.x, hoverHeight, transform.position.z), hoverHeightStrictness);
  
         var amountToBank : float = rigidbody.angularVelocity.y * bankAmount;
  
         bank = $$anonymous$$athf.Lerp(bank, amountToBank, bankSpeed);
  
         var rotation : Vector3 = transform.rotation.eulerAngles;
         rotation *= $$anonymous$$athf.Deg2Rad;
         rotation.x = 0;
         rotation.z = 0;
         rotation += bankAxis * bank;
         rotation *= $$anonymous$$athf.Rad2Deg;
         transform.rotation = Quaternion.Euler(rotation);
     }
  
     // thrust
     private var thrust : float = 0;
     private var turn : float = 0;
  
      function Thrust( t : float )
     {
         thrust = $$anonymous$$athf.Clamp( t, -1.0, 1.0 );
     }
  
     function Turn(t : float)
     {
         turn = $$anonymous$$athf.Clamp( t, -1.0, 1.0 ) * turnSpeed;
     }
  
     private var thrustGlowOn : boolean = false;
  
     function Update ()
     {
         var theThrust : float = thrust;
  
         if (playerControl)
         {
             thrust = Input.GetAxis("ship_Vertical");
             turn = Input.GetAxis("ship_Horizontal") * turnSpeed;
         }
  
         if (thrust > 0.0)
         {
             theThrust *= forwardThrust;
             if (!thrustGlowOn)
             {
                 thrustGlowOn = !thrustGlowOn;
                 Broadcast$$anonymous$$essage("SetThrustGlow", thrustGlowOn, Send$$anonymous$$essageOptions.DontRequireReceiver);
             }
         }
         else
         {
             theThrust *= backwardThrust;
             if (thrustGlowOn)
             {
                 thrustGlowOn = !thrustGlowOn;
                 Broadcast$$anonymous$$essage("SetThrustGlow", thrustGlowOn, Send$$anonymous$$essageOptions.DontRequireReceiver);
             }
         }
  
         rigidbody.AddRelativeTorque(Vector3.up * turn * Time.deltaTime);
         rigidbody.AddRelativeForce(forwardDirection * theThrust * Time.deltaTime);
 }
Hard to say with so much code. $$anonymous$$y first thought would be to comment out the bit that directly sets transform.rotation, and if that fixes it you'll know where to start looking.
Your answer
 
 
             Follow this Question
Related Questions
Floating Character, Water3 1 Answer
Simulating Water not working.. 1 Answer
Realistic boat physics? 0 Answers
Unexpected token if 1 Answer
Making realistic water 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                