Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Juhsi · Oct 24, 2013 at 08:12 PM · floatwaterfloatingice

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 :(

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Juhsi · Oct 25, 2013 at 07:40 AM 0
Share

hey, thanks for the answer (:

Ice won't rotation now!! and I figure out why not my character cannot stand on it!

Thanks!!!

avatar image jonnyhopper · Oct 25, 2013 at 08:51 AM 0
Share
  • 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.

avatar image Juhsi · Oct 27, 2013 at 02:04 PM 0
Share

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

avatar image Juhsi · Oct 27, 2013 at 02:06 PM 0
Share

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);
 }
avatar image jonnyhopper · Oct 27, 2013 at 02:42 PM 0
Share

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.

Show more comments
avatar image
0

Answer by SavaTim · Jun 12, 2019 at 11:21 PM

Look This https://youtu.be/W7tur5kpy6I

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges