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 MadJohny · Apr 01, 2014 at 06:26 PM · rotationcollider 2d

Unity colliders bug (2d box)

https://dl.dropboxusercontent.com/u/151460612/bug/bug.swf.html I recorded a little video to show you this bug, as you can see from the video, I have an empty object that works as pivot, and it's child should be a sprite, or even a sprite with collider, for the video I shown both, and same have same issue, when the object should look at the left side of the screen, it gets flipped(the z axis poinst to the other) and then the collider get's all messed up, how can I fix this issue? I started this project today and this is kinda pissing me off :/ I only have one script yet

 using System.Collections;
 
 public class KatanaScript : MonoBehaviour {
 
     public Transform katanaTarget;
     static bool katanaIsActive = false;
     public bool isTarget;
     public float rotateVelocity;
 
     void Update () {
         if (isTarget) {
             int number = 0;
             if (Input.GetMouseButton(0)) {
                 number++;
             }
 
             if (number >= 1) {
                 katanaTarget.gameObject.SetActive(true);
                 Vector2 pos = Input.mousePosition;
                 pos = Camera.main.ScreenToWorldPoint(new Vector2(pos.x, pos.y));
                 katanaTarget.position = pos;
                 katanaIsActive = true;
             }
             else {
                 katanaTarget.gameObject.SetActive(false);
                 katanaIsActive = false;
             }
         }
         else {
             if(katanaIsActive) {
                 transform.LookAt(katanaTarget.position);
                 transform.Rotate( new Vector3(0, -90, 0));
             }
         }
     }
 }

also, when the object is totally point up, it rotates 90º on the y axis, and when it gets over that (starts pointing at the left side) it rotates another more 90º.

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 MadJohny · Apr 02, 2014 at 02:37 PM

I've got this to work, the problem is that my script was rotating on all axis, causing weird behaviours for a 2d game, this is what I used instead:

         Vector3 vectorToTarget = katanaTarget.position - transform.position;
         float angle = Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg;
         Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);
         transform.rotation = Quaternion.Slerp(transform.rotation, q, Time.deltaTime * rotationVelocity);
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 Abdullah-Alaskari · Apr 02, 2014 at 02:21 PM

Hi There, Try to use rigidbody2d, as far as i know these are the only thing that can be rotated in 2d without bugging the collider.

Static RigidBody2d is good i think, maybe addTorque.

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 MadJohny · Apr 02, 2014 at 02:35 PM 0
Share

I'll answer my own question because I fixed it before any answers

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

21 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

Related Questions

Flip over an object (smooth transition) 3 Answers

Collider2Ds acting glitchy 0 Answers

Trying to clamp camera position causes it to get stuck for a few seconds. 1 Answer

Rotating Sprite 2D with JAVASCRIPT coding. 2 Answers

Adding a 45º rotation to a script 2 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