2d Movement Jumps to the Left


I’m beginning to use Unity and I’ve been following the excellent tutorials on Learn game development w/ Unity | Courses & tutorials in game design, VR, AR, & Real-time 3D | Unity Learn.

I’m on the last beginners video “2d Character controllers” Live Training 16 Dec 2013 - 2D Character Controllers - YouTube.

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.

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.

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…

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.