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 Dun4773124 · Aug 02, 2014 at 06:36 AM · c#2dcharactercontroller2d-platformer

2d Movement Jumps to the Left

Hello,

I'm beginning to use Unity and I've been following the excellent tutorials on http://unity3d.com/learn/tutorials/modules/beginner/2d.

I'm on the last beginners video "2d Character controllers" https://www.youtube.com/watch?v=Xnyb2f6Qqzg.

My character now have basic left and right movement that can flip. Only problem is when I move left his sprites jumps halfway across the cameras screen. I'm concerned that it may be because I'm using many sprites to build my character instead of the single sprite character that makes up the character in the tutorial. I may be wrong but I can't seem to find a solution.

I've gone over the code a few times and still cannot see my problem. In C# I have the following.

using UnityEngine; using System.Collections;

public class RobotController : MonoBehaviour {

     public float maxspeed = 10f;
     bool facingRight = true;
     
     void Start () 
     {}
     
     
     void FixedUpdate () 
     {
         float move = Input.GetAxis ("Horizontal");
         
         rigidbody2D.velocity = new Vector2(move * maxspeed, rigidbody2D.velocity.y);
         
         if(move > 0 &&!facingRight)
             Flip ();
         else if(move < 0 && facingRight)
             Flip ();    
     }
     
     void Flip()
     {
         facingRight = !facingRight;
         Vector3 theScale = transform.localScale;
         theScale.x *= -1;
         transform.localScale = theScale;
     }
 }

Any help is much appreciated.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Dogg · Aug 02, 2014 at 07:29 AM

I swear if I get down voted for this I'll...

I tried your script. I moved left and right no problem. I did the same thing as you(not having a single sprite sheet) and yet it still works for me. Maybe it's something that's not the script like your animations, rigidbody2D, or even colliders. I've done that tutorial before when I first started Unity, so if I remember correctly it happened to me once. Make sure you go over the video again and again. Even the smallest difference can affect your game. Sorry that's all I can say right now.

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 LSPressWorks · Aug 02, 2014 at 08:57 AM

Usually when this happens the object is moving too far per frame(the updates between fixedUpdate(), which I assume you're using)

The usual culprits are mass, drag and using the wrong update function...

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 Dun4773124 · Aug 02, 2014 at 04:21 PM

Thank you for your help. I was actually able to figure out my problem. Everything was correct except by character was not lined up evenly with my game object.

What I had to do was select game object and hit center on children. The parts making up my character moves in a few different directions and I had to redo my animations. Fortunately once I had everything lined up again it worked like a charm. Still learning the program so I'm sure it was a pretty rookie mistake.

Hopefully this helps someone else. Thank 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

Type"PathDefinition" does not contain a definition for "GetPathEnumerator" 0 Answers

Flipping parent object in 2d with negative x scale causes rotation issues for children gameobjects 2 Answers

Flipping a 2D Game object over time 1 Answer

2D games; Javascript or C#? 1 Answer

Spikes for a platformer game 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