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 /
  • Help Room /
avatar image
0
Question by maruska · Mar 18, 2016 at 10:04 PM · euleranglesquaternionslimits

Limit rotation within a volume

I'm working on a turret controller. The turret has a certain range of motion (it can't tip down past a certain point and it can't fire behind itself at a certain point).

I'm using a joystick for input and the joystick axes are mapped to different axes for Quaternion.AngleAxis rotations. The rotations work great, but the way I'm limiting the rotation doesn't. It works in the sense that it limits the rotation correctly, but I think because I'm totally halting the rotation calculation, it gets stuck and/or stops - it feels "sticky" at the edges. Pulling the joystick away from the limit-zone get things going again, but I'm looking for the turret to glide across the boundary I'm establishing.

I can't just test for Euler values, because many of the x,y,z Euler values are blended throughout the range of motion, so limiting it "in space" seems like the right starting point.

Thoughts?

 using UnityEngine;
 using System.Collections;
 
 public class TargetInput : MonoBehaviour
 {
         
         public float deadzone = 0.25f;
         public float angularVelocity = 0.5f;
         public GameObject target;
         private Vector2 stickInput;
         private Quaternion lastRotation;
 
         void Update ()
         {
                 stickInput = new Vector2 (Input.GetAxis ("Horizontal"), Input.GetAxis ("Vertical"));
                 if (stickInput.magnitude < deadzone) {
                         stickInput = Vector2.zero;
                 } else {
                         
                         Vector3 axisX = transform.forward;
                         Vector3 axisY = transform.right;
 
                         transform.rotation = Quaternion.AngleAxis (stickInput.x * angularVelocity, axisX) * transform.rotation;
                         transform.rotation = Quaternion.AngleAxis (stickInput.y * angularVelocity, axisY) * transform.rotation;
 
                         if (target.transform.position.z < 0.1f || target.transform.position.y > 3.8f) {
                                 transform.rotation = lastRotation;
                         }
 
                         lastRotation = transform.rotation;
                 }
         }
 }
Comment
Add comment · Show 2
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 maruska · Mar 22, 2016 at 07:46 PM 0
Share

This might help a bit. The turret is double articulated and I'm using a target object to drive the articulation. Basically I want the target to rotate within the region I've highlighted on the dome. It's not quite the full upper hemisphere, and the rear quarter of the dome is truncated. In the code above, I test if the target object has rotated outside of the bottom plane or the back plane and pause the calculation. But I'm getting a "sticky" behavior at the edges rather than it just deflecting off the boundary smoothly.

alt text

screen-shot-2016-03-18-at-41640-pm.png (232.9 kB)
avatar image maruska maruska · Mar 22, 2016 at 08:01 PM 0
Share

falcon cannon video

Another bit is that I'm using the resultant look-at angles to drive a couple of servos. This part works fine as shown in the video - but in this iteration, I was driving Euler Angles directly (which resulted in gimbal lock at the north pole). I'm hoping to avoid that by using the Quaternions, but it's causing other problems.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Quaternions to EulerAngles weird x-axis interaction 1 Answer

Get single axis from gyroscopic input (iOS) 0 Answers

Why Quaternions? 2 Answers

Is it possible to rotate 1 axis with Quaternions without using EulerAngles? 1 Answer

problem setting rotation 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