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
1
Question by Kassai · Sep 03, 2014 at 01:18 PM · animation2dtransform.position

sprite offset in game but not in scene

I have a small problem with my current project and hope you guys can help me out.

I'm making a small 2D game (and i mean 2D -> 2d mode, 2d colliders, 2d physics, sprites, etc.).

For some reason it seems like the arm of my mage character gets offset over multiple walking cycles (not 1, so not a simple mistake in the animation). Actually it's not just the arm, but that one is most noticeable.

The strangest part is, that the change is only visible in the game view during play, it seems fine in the scene view.

Also, the (x,y,z) coordinates seem to be as they should be (you might detect a slight offset in the "arm_offset_problem.jpg" but that is caused by the breathing idle animation).

I checked that there is no offset between the start and end of the walking animation(though that shouldn't have any impact anyway since it loops).

I restarted unity and build the project, thinking it might be a play mode problem but it's the same in the build game.

There is only one script that impacts the movement at all. It's placed on the "Chibi_Mage" GameObject and lets me move around the mage (simple transform movement, don't need physics yet; changes apply to the parent GameObject "Chibi_Mage" so it shouldn't affect the different child sprites at all).

Below you will find the movement script and a few pictures to get a better feeling for the setup.

I'm using Unity version 4.5.2f1.

 using UnityEngine;
 using System.Collections;
 
 public class ChibiBattleMoves : MonoBehaviour {
 
     public float walkspeed = 10f;
     public bool turnblock = false;
 //    private Vector2 moveDir = new Vector2(0,0);
     private Animator myAnimator;
     // Use this for initialization
     void Start () {
         myAnimator = gameObject.GetComponent<Animator>();
     }
     
     // Update is called once per frame
     void Update () {
         Vector3 move = new Vector3(Input.GetAxis("Horizontal"),
                                    Input.GetAxis("Vertical"), 0);
 
         gameObject.transform.position += move * walkspeed * Time.deltaTime;
 
         myAnimator.SetFloat("AnimWalkSpeed", move.magnitude);
 
 
 
         if(move.x > 0 &&
            turnblock == false)
             gameObject.transform.localScale = new Vector3(
                 Mathf.Abs(gameObject.transform.localScale.x),
                 gameObject.transform.localScale.y,1);
 
         if(move.x < 0 &&
            gameObject.transform.localScale.x > 0 &&
            turnblock == false)
             gameObject.transform.localScale = new Vector3(
                 gameObject.transform.localScale.x * -1,
                 gameObject.transform.localScale.y,1);
 
 
         /*
         if(gameObject.transform.rotation.y == 0 && move.x > 0)
             gameObject.transform.localRotation = Quaternion.Euler (0,180,0);
         if(gameObject.transform.rotation.y == 180 && move.x < 0)
             gameObject.transform.localRotation = Quaternion.Euler (0,180,0);
             */
     }
         
 }







alt text

alt text

alt text

alt text

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 Pyrian · Sep 03, 2014 at 02:56 PM 0
Share

Off-hand, I'd guess you're using a perspective camera when you really should be using an orthographic camera.

avatar image Kassai · Sep 03, 2014 at 06:07 PM 0
Share

That was it! Thank you very much ^^'. I didn't keep in $$anonymous$$d that the 2D mode button only applies to the scene viewport. How do I mark this as answered?

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Pyrian · Sep 03, 2014 at 06:23 PM

Off-hand, I'd guess you're using a perspective camera when you really should be using an orthographic camera.

Comment
Add comment · Show 2 · 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 Ash-Blue · Sep 14, 2016 at 04:52 AM 0
Share

I just spent an hour trying to figure out what was causing this. You sir are a life-saver.

avatar image dpjr96 · Jul 13, 2021 at 06:51 PM 0
Share

this was part of my problem too. The other thing to check is your z axis. Despite my being in 2D the whole time, my parent sprite had somehow gotten moved 0.7 on the z. So annoying. Thanks for the help.

P.S. If you're having this problem and its not your camera or your z axis, you could try adding your sprites to a sorting group or changing the "Order in layer" in the sprite renderer > additional settings

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Animation does not start 1 Answer

Damage gets applied multiple times per frame 0 Answers

Damn, HOW CAN I KNOW, IF MY 2d ANIMATION SPRITE IS FINISHED??!! 0 Answers

SpriteManager 2 1 Answer

Best way to do animate soldier? 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