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 May 01, 2017 at 08:20 PM by taymakes for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by taymakes · May 01, 2017 at 04:26 PM · 2dmovementtransform

2D Sprite Scroller Shooter - Face Right When Standing still

I'm quite new to coding/Unity and I'm making a horizontal scroller shooter for an school project. My Player animations were all facing direction of movement just fine until I changed x-axis movement in input manager to joystick instead of wasd. Now the Player faces left on default even if I was just moving right.

Is there an easy band-aid fix for this? It's just for a demo, I'm an artist not coder, so if I could insert a line of code that makes the player face right when not moving that would be perfect.

My code is below :)

 // Use Start for initialization

 void Start () {
     rb = GetComponent<Rigidbody2D> ();
     InvokeRepeating ("Shoot", 0.0f, 1.0f / bulletsPerSecond);
     //this is a timer for 5x a second we are calling the function "shoot"
 }

 void Shoot(){
     canShoot = true;
 }

 // Update is called once per frame

 void Update(){
     if (Input.GetButton ("Jump") && canShoot) {
         Vector2 spawnPoint = new Vector2 (transform.position.x, transform.position.y);
         Rigidbody2D bulletInstance = Instantiate (bulletPrefab, spawnPoint, transform.rotation) as Rigidbody2D;
         bulletInstance.AddForce (transform.right * bulletSpeed);
         canShoot = false;
     }

         // X axis
     if (transform.position.x <= -7.61f) {
             transform.position = new Vector2(-7.61f, transform.position.y);


     } else if (transform.position.x >= 20f) {
         transform.position = new Vector2(20f, transform.position.y);
         }

         // Y axis
     if (transform.position.y <= -0.84f) {
         transform.position = new Vector2(transform.position.x, -0.84f);
         } else if (transform.position.y >= -0.01f) {
         transform.position = new Vector2(transform.position.x, -0.01f);
         }

     }


 void FixedUpdate ()
 {
     xSpeed = Input.GetAxis ("Horizontal") * speed;
     ySpeed = Input.GetAxis ("Vertical") * speed;
     rb.velocity = new Vector2 (xSpeed, ySpeed);

 }
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 webcam · May 01, 2017 at 05:21 PM 0
Share

Hey mate, maybe I'm not seeing it here but where are you flipping your sprite? Are you manually flipping the scale somewhere or do you have a move left animation and a move right animation?

If so you must be setting the scale or a float in your animator somewhere.

avatar image taymakes webcam · May 01, 2017 at 08:20 PM 0
Share

I have a move left and a move right animation! I ended up figuring out, I just changed the horizontal value of "dead" to -1 in the input manager and that fixed it! Not quite sure why but hey pleased it worked! Thanks anyway!

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Stop Moving When Not Touching Screen? 1 Answer

Rotating an object towards target on a single axis 2 Answers

Sprite moving too far/fast 1 Answer

Problem when rotating sprite and moving it foward 1 Answer

Sprite is not shown moving 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