Huge problem with moving my player

Hello!

I would ask you if you’d know how to find the problem I have.
I made my game in Unity, with assets that I’ve made within Blender.
The problem is I can’t move the player.
I tried everything, went on many forums, asked my brother who work as developers and he wasn’t able to find my problem, so I hope you will!

So, I have a mesh, and I added to it a rigidbody component and a boxcollider, and I then added the script founded there : https://unity3d.com/learn/tutorials/projects/roll-a-ball/moving-the-player?playlist=17141
I’ve just changed the vector3 to a vector2 because I didn’t need the Z axis. I tried with the original script and with the one modified and both didn’t work. I went to the input settings, put “left” and “right” to use the arrow and nothing worked.
Could you tell me where the problem is?
If you need to, I can send you screenshots of my scene!
Thanks in advance :slight_smile:

There are two things you need to clarify here. 1; Is the character static state (no bones/rigged?) or is it a humanoid model with boned/rigged?

1; If it is a static state object with no moving parts and you added the script to the player model itself it should work. Also make sure its tagged “Player” and not just named Player.

2: Rigidbody in Unity is not the same as Rigged Body(bones). Its for your setting with gravity, position, etc.

The other is what version of Unity are you using? You have to also be certain what sort of movement you are looking for because the script will also determine of you are just moving around or if you will pass through things.

Without seeing the script or knowing what sort of model you are trying to use makes helping you properly rather difficult.

Here is an example of some basic script concepts that don’t call for animations of a character with bones/rigged body, but you still need to have rigid body and some sort of collider on it.

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour
{

    public float moveSpeed;

    // Use this for initialization
    void Start()
    {
        moveSpeed = 50.0f;
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(moveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, moveSpeed * Input.GetAxis("Vertical") * Time.deltaTime);

    }
}

Notice there are no rotations in this script. Its just for moving forward and backward or side to side. However, there is no force detection. In void start you have the speed here set at 50 which is really fast, so you would need to figure out what works best and can set it in the script or in the editor.

Now compare the one from rollerball

public float speed;

    private Rigidbody rb;

    void Start ()
    {
        rb = GetComponent<Rigidbody>();
    }

    void FixedUpdate ()
    {
        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");
        Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
        rb.AddForce (movement * speed);
    }
}

and the one from SpaceShooter

void FixedUpdate ()
    {
        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");

        Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
        rigidbody.velocity = movement * speed;
        rigidbody.position = new Vector3 

and the one without the animations part from Survival Shooter

void FixedUpdate ()
{
// Store the input axes.
float h = Input.GetAxisRaw (“Horizontal”);
float v = Input.GetAxisRaw (“Vertical”);

Notice the ones from Unity all say the same thing more or less, just some parts abbreviated.

Then you have more or less this version here from this link(Unity Connect)

{
    public float moveSpeed = 10f;
    public float turnSpeed = 50f;
    
    
    void Update ()
    {

//Note this set is just for moving foirward/backward//

        if(Input.GetKey(KeyCode.UpArrow))
            transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
         if(Input.GetKey(KeyCode.DownArrow))
            transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);

//Note this is for the rotations left to right//

        if(Input.GetKey(KeyCode.LeftArrow))
            transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
        if(Input.GetKey(KeyCode.RightArrow))
            transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
    }
}

Now then there is this version that locks you to the ground and allows the interaction needed,

//Feed moveDirection with input.

        transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);

        Vector3 forward = transform.TransformDirection(Vector3.forward);

        float curSpeed = speed * Input.GetAxis("Vertical");

        controller.SimpleMove(forward * curSpeed);

I hope this was helpful, and note I personally cannot get animated characters working correctly on my end, and this is all for static state character objects, like a craft of some sort.

Hello!

First, I wanna say thank you because you told me everything that I needed for my game! :slight_smile:
Then, I used the first script and I’ve modify it a little bit with the help of my brother and he added what was needed more specifically for my game. Here’s the script:
using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour
{

private float moveSpeed;
private const float JUMP_UNIT = 1.5f;
private const float MOVE_UNIT = 0.5f;
private bool isJumping = false;

private Vector3 nextPosition = Vector3.zero;

// Use this for initialization
void Start()
{
    moveSpeed = 50.0f;
    Physics.gravity = new Vector3(0, -75.0F, 0);
}

public void Update4()
{
    if (Time.time < 2)
        return;

    if (nextPosition.Equals(Vector3.zero)) // Initialize next position
        nextPosition = transform.position;

    if (nextPosition != transform.position) // Wait till player has reached next position

Again, thank you so much for your time and your experience! :slight_smile:
return;

    if (Input.GetKey(KeyCode.UpArrow))
        Jump();
    if (Input.GetKey(KeyCode.DownArrow))
        Bend();
}

private void Jump()
{
    transform.Translate(0.5f, 0f, 0f);
    nextPosition += new Vector3(0.5f, 0f, 0f);
}

private void Bend()
{

}

// Update is called once per frame
void Update()
{
    float x = 0;
    float y = 0;

    if (Input.GetKey(KeyCode.UpArrow))
        x = -JUMP_UNIT;
    if (Input.GetKey(KeyCode.DownArrow))
        x = 0;
    if (Input.GetKey(KeyCode.LeftArrow))
        y = MOVE_UNIT;
    if (Input.GetKey(KeyCode.RightArrow))
        y = -MOVE_UNIT;
    
    if (x < 0) // Player tries to jump
    {
        if (isJumping)
            x = 0; // Avoid double-jumps
        isJumping = !isJumping;
    }

    if (Input.GetKey(KeyCode.DownArrow))
    {
       // transform.localScale -= new Vector3(0.001f, 0f, 0f);
    } else
    {
        //transform.localScale += new Vector3(0.001f, 0f, 0f); ;
    }

    transform.Translate(
        moveSpeed * x * Time.deltaTime,
        moveSpeed * y * Time.deltaTime,
        0f
    );
}

}