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 /
avatar image
0
Question by ScarcticCG · Sep 02, 2016 at 01:44 PM · transformdebuggingcantwhats-wrong

transform.localscale not working after update

Hello

I have a script for my enemy AI which flips the object and applies velocity to it (moves it left or right) when it hits an obstacle. I recently updated Unity to the newest version, before the update this worked like a dream but now on hitting the obstacle the AI turns correctly but continues in his previous direction anyway. I'm very confused as I have changed absolutely nothing. If anyone can see any mistakes I may have made or anything I would be very appreciative, I'm at my wits end right now.

Here is the method for turning the AI

 void turn(float prevDirection, float newDirection)
     {
         if (walkingDirection == prevDirection)
         {
             walkingDirection = newDirection;
             transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, 1);
             if (walkingDirection == 1)
             {
                 isFacingRight = true;
             }
             else if (walkingDirection == -1)
             {
                 isFacingRight = false;
             }
         }
     }

here is the method for applying the movement to the AI

     void Move(float speed)
     {
         velocity.x = speed * Time.deltaTime;
         velocity.y += gravity * Time.deltaTime;
         controller.Move(walkingDirection * velocity * Time.deltaTime);
     }

and finally the if statement (in the update method) where these are applied:

         if(!alert && !caution)
         {
             spr.color = Color.blue;
             Move(100);
             positionSet = false;
             alertCoolDown = 1;
 
             if (controller.collisions.right)
             {
                 turn(1, -1);
             }
             else if (controller.collisions.left)
             {
                 turn(-1, 1);
             }
         }

I have included a .gif of the error in question so hopefully you can see what I mean: https://s21.postimg.org/tv7wcqyef/bug.gif

ANY help at all would be amazing. Thank you very much.

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 donlew · Oct 30, 2016 at 12:22 PM 0
Share

@ScarcticCG I have the same error. Did you find a fix for this?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ScarcticCG · Nov 01, 2016 at 04:36 PM

@donlew I certainly did! Had to email customer support to find a fix, which is bananas and probably says a lot about Unity Documentation. Anyway, I will c+p the email here for your convenience.

So I have talked with the developer and it seems that "transform.Translate(velocity);" has changed behaviour since 5.4(The X velocity is -0.04f but when added to the transform that has local scale X to -1, it causes the Transform to be moved right and not left as previous.)

Here is a fix for your issue:

There is now an overload of this method that allows you to specify which space to translate in i.e. self (local) or world.

https://docs.unity3d.com/ScriptReference/Transform.Translate.html

https://docs.unity3d.com/ScriptReference/Space.html

Changing the method from:

transform.Translate(velocity);

to

transform.Translate(velocity, Space.World);

seems to solve the issue.

Hope this helps you!

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Input.GetMouseButton NEVER returns false 1 Answer

Find out what's changing the Transform. 2 Answers

parented/constrained object transform lags when moving character 0 Answers

Get direction of moving sphere? 1 Answer

What the hell? Cannot convert float to int PROBLEM. 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