Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Apr 25, 2019 at 05:56 AM by K-Anator for the following reason:

Brain fart.

avatar image
0
Question by K-Anator · Apr 25, 2019 at 03:06 AM · physicsquaternionspaceshiphovercraft

Rotating an object based on velocity.

I have a pair of thrusters with (for lack of a better term) flappy things on them, and I want them to move in relation to the players velocity. In order to do this, I've pulled some code out of the AeroplaneControlSurfaceAnimator from the Standard Asset's sample scenes and bastardized it to fit my needs.


I don't fully understand most of what's happening in there, but for the most part it works the way I'd like. Except I just noticed that my console is constantly spitting out "UnityEngine.Transform.get_localRotation () <0x1983c30a460 + 0x00072> in :0" and I'm not exactly sure why.


Here is my bloody and beaten script if anyone can explain to me what's going on and where it's getting this null from.

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class AnimationController : MonoBehaviour
 {
 
     [SerializeField] private float m_Smoothing = 5f; // The smoothing applied to the movement of control surfaces.
     [SerializeField] private ControlSurface[] m_ControlSurfaces; // Collection of control surfaces.
 
     private Rigidbody player;
 
     // Start is called before the first frame update
     void Start()
     {
         player = GetComponent<Rigidbody>();
 
         foreach (var surface in m_ControlSurfaces)
         {
             surface.originalLocalRotation = surface.transform.localRotation;
         }
 
     }
 
     private void Update()
     {
         foreach (var surface in m_ControlSurfaces)
         {
             switch (surface.type)
             {
                 case ControlSurface.Type.Elevator:
                     {
                         // Elevators rotate negatively around the x axis, according to the plane's pitch input
                         Quaternion rotation = Quaternion.Euler(0f, 0f, surface.amount * player.velocity.z);
                         RotateSurface(surface, rotation);
                         break;
                     }
                 case ControlSurface.Type.Rudder:
                     {
                         // Rudders rotate around their y axis, according to the plane's yaw input
                         Quaternion rotation = Quaternion.Euler(0f, surface.amount * player.velocity.z, 0f);
                         RotateSurface(surface, rotation);
                         break;
                     }
             }
         }
     }
 
 
     private void RotateSurface(ControlSurface surface, Quaternion rotation)
     {
         // Create a target which is the surface's original rotation, rotated by the input.
         Quaternion target = surface.originalLocalRotation * rotation;
 
         // Slerp the surface's rotation towards the target rotation.
         surface.transform.localRotation = Quaternion.Slerp(surface.transform.localRotation, target, m_Smoothing * Time.deltaTime);
     }
 
 
     // This class presents a nice custom structure in which to define each of the plane's contol surfaces to animate.
     // They show up in the inspector as an array.
     [Serializable]
     public class ControlSurface // Control surfaces represent the different flaps of the aeroplane.
     {
         public enum Type // Flaps differ in position and rotation and are represented by different types.
         {
 
             Elevator, // Horizontal flaps used to adjusting the pitch of a plane, rotate on the x axis.
             Rudder, // Vertical flaps on the tail, rotate on the y axis.
 
         }
 
         public Transform transform; // The transform of the control surface.
         public float amount; // The amount by which they can rotate.
         public Type type; // The type of control surface.
 
         [HideInInspector] public Quaternion originalLocalRotation; // The rotation of the surface at the start.
     }
 }
Comment
Add comment · Show 1
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 K-Anator · Apr 25, 2019 at 05:56 AM 0
Share

Apparently I need to go to bed. Turns out that you should populate all the fields in the animator. I had only done the 4 flaps on the left side, and left an additional 4 empty elements.

This script does not like that.

1 Reply

  • Sort: 
avatar image
0

Answer by K-Anator · Apr 25, 2019 at 03:22 AM

I should also note, when I double click the error it points at line 57: surface.transform.localRotation = Quaternion.Slerp(surface.transform.localRotation, target, m_Smoothing * Time.deltaTime);

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

Follow this Question

Answers Answers and Comments

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

Related Questions

Constant 3D rotation (torque, angular acceleration, etc) GLOBAL to object in space? 1 Answer

How to make any dice have a given face(int) face up? 1 Answer

Player Control. Roller Ball with Cube Acceleration. 1 Answer

Game Object rotation sometimes doesn't match defined quaternion 0 Answers

vehicle falls off loop (possible physics bug?) 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