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 ExpertKiD · Nov 29, 2013 at 05:13 AM · 2djavascript2d-platformerscale

Flipping Error! Spritesheet and JS!

Well, I have a sprite sheet and it only contains all movement in the right only!

So, no left movements!!

I checked some answers and found that if I changed the scale to negative, it'll work also for the left!! It mirrors the sprite!

So, I checked it in the inspector, it works! Both for left and right direction!

But, when I implement the same technique in the script during play, it does nothing!!

The local Scale has no effect at all!!

The script is as follows!!

 var walkSpeed                     : float     = 1.5;                    //speed of standarad wlak!
 var runSpeed                     : float     = 2.0;                    //speed of run
 var fallSpeed                     : float     = 2.0;                    //speed of falling down
 var walkJump                     : float     = 6.2;                    //jump height from walk
 var runJump                        : float     = 9.0;                    //jump height from run
 var crouchJump                     : float     = 10.0;                    //jump height from crouch
 var gravity                     : float     = 20.0;                    //force applied on char
 var startPos                    : float     = 0.0;                    //location for start position
 
 var moveDirection                 : int         = 1;                    //direction player facing || 1 right, 0 left
 
 private var velocity             : Vector3    = Vector3.zero;            //speed of player and direction
 private var jumpEnable            : boolean      = false;                //toggle for jump standard                
 private var runJumpEnable        : boolean      = false;                //toggle for run jump    
 private var crouchJumpEnable    : boolean      = false;                //toggle for crouch jump    
 
 
 
 function Update()
 {
     var aniPlay = GetComponent("aniSprite");                        //set aniPlay to aniSprite
         
     var controller : CharacterController = GetComponent(CharacterController);    //set controller to CharacterController
     
     if(controller.isGrounded)
     {
         jumpEnable             = false;                            //reset jumps
         runJumpEnable         = false;                            //reset jumps
         crouchJumpEnable    = false;                            //reset jumps
     
         
         velocity = Vector3(Input.GetAxis("Horizontal"),0,0);
         
         
         if(Input.GetKeyDown("Horizontal")>0.1f)
         {
             transform.localScale = Vector3(Mathf.Abs(transform.localScale.x,transform.localScale.y,transform.localScale.z);
         }
         
         if(Input.GetKeyDown("Horizontal")<0.1f)
         {
             transform.localScale = Vector3(-transform.localScale.x,transform.localScale.y,transform.localScale.z);
         }
         
         
         
         if(velocity.x==0)                    //idle left
         {
         
             aniPlay.aniSprite(7,3,3,1,1,10);                    //animation call to spritesheet
         }
         
         if(velocity.x>0)
         {
             
             aniPlay.aniSprite(7,3,0,0,6,12);
             aniPlay.aniSprite(7,3,0,1,4,12);
         }
         
         
         if(velocity.x<0)
         {
             
             aniPlay.aniSprite(7,3,0,0,6,12);
             aniPlay.aniSprite(7,3,0,1,4,12);
         }
     }
         
     velocity.y -= gravity * Time.deltaTime;                        //set gravitiy
     
     controller.Move(velocity * Time.deltaTime);
 }

So, am I doing anything wrong??

Please do help!! I can't just let the player work only on the right direction at all!!

Everytime I click play!!

The quads Z scale = 0, and X scale goes negative!

I only need to change the X scale to negative when left arrow is pressed! X scale positive when right arrow is pressed!!

Also, z scale should remain 0.5f at all time!!

y scale also fixed!

But, every time I click play Z scale goes to 0!

Is it because of using quad!!

Could you please direct me on this!!

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

16 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

Related Questions

Simple Status UI (scale the distance) 1 Answer

2D games; Javascript or C#? 1 Answer

2D Character Movement Issues 1 Answer

2d enemy ai 0 Answers

How expensive is scaling in 2D unity? Is it better to pre-scale? 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