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 SomeRandomGuy · May 07, 2013 at 07:56 AM · rotationslerpquaternion.lookrotation

making an object below this object follow rotation on y axis

So I've been trying to get a simple script done where I have a little animated mesh that is supposed to become visible when the player comes close enough to the ground, and follows the rotation of the player's ship on the Y axis. I've tried the following, but for some reason there is absolutely no rotation on the animated mesh at all. The rest is working fine, but for some reason I cannot seem to fix the rotation of this thing.

 #pragma strict
 var maxDistance: int = 30;
 var dustFX: GameObject;
 private var dustInstance: GameObject;
 
 function Awake()
 {
     if(dustFX==null)
     {
         this.enabled = false;
     }
     dustInstance = Instantiate(dustFX,transform.position,transform.rotation);
     dustInstance.SetActive(false);
 }
 
 function Update()
 {
     var hit: RaycastHit;
     
     if (Physics.Raycast (transform.position, -Vector3.up, hit))
     {
         if(hit.distance<maxDistance)
         {
         
             dustInstance.SetActive(true);
             dustInstance.transform.position = hit.point;
             
             var newRotation = Quaternion.LookRotation(dustInstance.transform.position - transform.forward*10);
 
             newRotation.x = 0.0;
 
               newRotation.z = 0.0;
 
             dustInstance.transform.rotation = Quaternion.Slerp(dustInstance.transform.rotation, newRotation, Time.deltaTime * 8);
         }
         else if(hit.distance>maxDistance)
         {
             dustInstance.SetActive(false);
         }
     }
 }

To clear things up a bit, this script is attached to the player ship, so transform refers to the player ship's transform. What I think I'm doing is making a lookRotation from the dustInstance to a point 10 units from the player ship's front. Then the X and Z values of that rotation are set to 0, to make it a Y only rotation. Then I apply the rotation with Quaternion.Slerp.

Anyone see what I'm doing wrong here?

EDIT: okay, so after some asking around I found out that we'd want the animated mesh to be under the ship, using the normal of the raycasthit to position it. however this makes the whole rotation thing even harder. Here's the current script:

 #pragma strict
 var maxDistance: int = 30;
 var dustFX: GameObject;
 
 function Awake()
 {
     if(dustFX==null)
     {
         this.enabled = false;
     }
     dustFX.SetActive(false);
 }
 
 function Update()
 {
     var hit: RaycastHit;
     
     if (Physics.Raycast (transform.position, -transform.up, hit))
     {
         if(hit.distance<maxDistance)
         {
         
             dustFX.SetActive(true);
             dustFX.transform.position = hit.point;
             dustFX.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
             dustFX.transform.localEulerAngles.y = transform.localEulerAngles.y;
         }
         else if(hit.distance>maxDistance)
         {
             dustFX.SetActive(false);
         }
     }
 }

Changed a bunch of things, the dustFX object is now a child object of the player ship, and is just being moved to the hit normal when the ship is close to something. I've tried changing the y axis rotation of the dustFX object to the ship's y axis, but this didn't work. Strange rotations and such.

I have no idea how to get this to work now, but I'm gonna continue fiddling with it. Maybe I'll find a way, haha!

EDIT(again):

I believe the best way to do this would be to align only the z and x axis to the hit normal, however fromtorotation does not seem to work for that purpose.

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

0 Replies

· Add your reply
  • Sort: 

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

12 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

Related Questions

Making Player Rotation Smoother 0 Answers

How do I swap two objects without them colliding ? 1 Answer

Slerp/Rotational Problem Query 1 Answer

Slerp Problem?: Enemy in Constant Rotation! 1 Answer

Can't figure out how to make my raycast obstacle avoidance less jittery 3 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