URGENT Player won't walk/move but animations plays when key is triggered -Script/Animation/Component

So as the title says “player won’t walk/move but animations plays when key is triggered”. When I press A and D keys, they work/trigger the animation but they do not make the player move/walk. It seems the player is stuck in one position although the animations move…I’m not sure what the problem is as I have checked the animation and the scripts along with components. Is there anyone who could help me out? I am happy to send them/you a copy of my project/game just for fixing?? Also, I have tried many solutions to make the character jump with animation when pressing W but it won’t work…I tried to add a groundcheck and it still does not work…

What I would do, if I were you, is try to narrow it down to the code that you find most suspect and insert it directly into this thread. Use the insert code feature to make it pretty.

3237714--248761--upload_2017-9-28_20-11-49.png

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
private Rigidbody2D myRigidbody;

private Animator myAnimator;

[SerializeField]
private float movementSpeed;

private bool facingRight;

// Use this for initialization
void Start ()
{
  facingRight = true;
  myRigidbody = GetComponent<Rigidbody2D> ();
  myAnimator = GetComponent<Animator> ();
}
// Update is called once per frame
void FixedUpdate ()
{
  float horizontal = Input.GetAxis ("Horizontal");

  HandleMovement (horizontal);

  Flip(horizontal);
}

private void HandleMovement(float horizontal)
{

  myRigidbody.velocity = new Vector2 (horizontal * movementSpeed, myRigidbody.velocity.y); //x = -1, y = 0

  myAnimator.SetFloat ("Speed", Mathf.Abs(horizontal));
}

private void Flip(float horizontal)
{
  if (horizontal > 0 && !facingRight || horizontal < 0 && facingRight)
  {
   facingRight = !facingRight;

   Vector3 theScale = transform.localScale;

   theScale.x *= -1;

   transform.localScale = theScale;
  }
 
}
}

Okay sure thing. Though, I did say above that I do not know whether it is an scripting/component issue thats why I offered to upload the entire project for inspection. This code however does not have the jump as I do not know how implement it…The only action is the running which triggers speed parameter.

Okay. So, when I tried this script, the movement speed defaulted to zero. Naturally, the player wouldn’t move. When I used the inspector to change it to one, the player moved the way I would expect.

If you look at your player instance in the inspector and the movement field is zero, you could try changing the speed and see if it works the way you want. If the movement speed is nonzero, and your player is still stuck, we can eliminate this script as the source of the problem.

Hi there,

So I have set the movement speed to 5 and still not moving…

So now we know it’s not that script, then. What else in your project might be the culprit?

I’m assuming your Horizontal input axis has the default configuration, but it can’t hurt to double-check that.

To be honest, it’s quite hard to say what the possible culprits might be. That is why I am offering you a chance to download my project file to determine what is the culprit as I myself cannot figure out?

You might find a taker but I have a day job and two children under two. So I cannot commit to something like that as I would likely not be able to follow through. I already push the limit with how much time I spend on the forums and answers board for Unity.

If you upload a small scene with just the relevant bits, I or someone might take a look at it :slight_smile:
If you’re still stuck…

Okay, since you put it that way, I guess its a no even though I just want a short analysis …Since its not the script causing the problem, then it must be something in the components setup (can’t confirm).

That would be very much helpful :smile:. You can’t imagine the complexity of having to explain this issue as I am not a developer so I cannot use your gaming terms. Would you prefer me to upload the entire folder or?

The most ideal upload would be that you export just the character (that has its components + scripts) as a package and post that :slight_smile: Maybe the animator controller + animations , too.
Whatever is small enough to test what’s not working lol :slight_smile:

I’m not too sure how to do do that but would I be able to convert it to a zip file then send it to you privately?

One of the menus at the top lets you export a package…

Assets → export package
Then you’ll see a list of stuff in your project. Just deselect all and select the ones that you think I’ll need and then save the package and drag-drop it into the forum thread here. :slight_smile:

Okay here you go. Look forward to your response and thanks :p. The main character’s name for this scene (SpeedTweaking) we’re focussing is “character”. This character has all the body parts. Just wanted to point this out as you might be confuse. Please ignore the other player. It’s strange how the character does not move/walk… Feel free to change anything to make it fixable.

Here is the link/url to the file package > https://ufile.io/ycbbe

I looked briefly and it seems like your character is a mess of rigidbodies and colliders overlapping each other, and the movement script is attached to one of the child rigidbodies. Unless you have some really good reason, you should just have one rigidbody and one collider for the character, on the topmost level of the character, and put the movement script on that.

Okay, you didn’t exactly do what I asked at all lol
You sent the whole scene… sigh

Sorry, it’s over my head how this is working… Honestly, I think you have too many rigidbodies and probably too many colliders…
Plus, the character is offset some crazy amount and so on… many issues that are odd and or I don’t understand - sorry :slight_smile:

I see @makeshiftwings responded while I was browsing the project. I attempted to move stuff in a similar design to how he suggested, and ran into a number of issues.
But that setup would be the best. 1 rigidbody and 1 collider is plenty. I would try a capsule. Make sure the animations work how you want… like when I was trying it, the char moved + 400 ish on the ‘x’ axis just by turning on the animator and he sat there… sigh.

At the end, too much to fix right now for me :slight_smile:

So do you suggest for the “character” I just make it so that that is the only one that has rigibody2d and collider? remove all colliders and rigibody for each body part?

So do you suggest for the “character” I just make it so that that is the only one that has rigibody2d and collider? remove all colliders and rigibody for each body part?