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 Rally Raghavan · Mar 13, 2011 at 09:22 PM · quaternionrotateforcespin

Rotating a boat on two axes with force.

var strength : float = 10.0f; var damping : float = 10.0; function Update () { if(Input.GetKeyDown(KeyCode.Mouse0)) { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); var hit : RaycastHit;

     if (Physics.Raycast(ray, hit)) 
     {
         var delta = transform.position - hit.point ;
         rigidbody.AddForce(delta.normalized * strength, ForceMode.Impulse);
         // Look at and dampen the rotation
         var lookDirection = Quaternion.LookRotation(hit.point - transform.position);
         lookDirection.y = 0;
         Quaternion targetRotation = Quaternion.LookRotation(lookDirection,Vector3.up);
         transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * damping);

     }
 }

}

This is the code i used to let a boat move when clicking on a plane, to keep it look like the boat moves when we create ripple. Force works fine. But there is some problem with the spinning part.

Quaternion targetRotation = Quaternion.LookRotation(lookDirection,Vector3.up);

This part alone says some semi colon error. Please help me in discovering what error it is.. thanks.

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 Rally Raghavan · Mar 18, 2011 at 07:09 AM

I found the answer on my own. the error is rectified.

var rotation = Quaternion.LookRotation(hit.point - transform.position);
            transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);

this is the proper code.

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
avatar image
0

Answer by efge · Mar 13, 2011 at 10:31 PM

It tries to split this line into two (no matter if it is useful or not):

Quaternion; 

and

targetRotation = Quaternion.LookRotation(lookDirection,Vector3.up);
Comment
Add comment · Show 1 · 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 Rally Raghavan · Mar 14, 2011 at 07:38 AM 0
Share

No, this answer didn't work out.. It showed one more just one more error.

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

No one has followed this question yet.

Related Questions

Orientation Vs. Rotation: How do I specify more than 360deg rotation for a quaternion, in the editor? 1 Answer

Rotate Gameobject by vertex shader with quaternion 0 Answers

AirPlane-Like Rotation ( like in GTA games) 1 Answer

How can i flip a ragdoll ? 1 Answer

Add force at position Question 1 Answer


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