Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question help me I have sliding

Discussion in 'Scripting' started by hofnergluke, Apr 28, 2022.

  1. hofnergluke

    hofnergluke

    Joined:
    Apr 28, 2022
    Posts:
    3
    I copy pasted this player movement script and it slides a whole lot and is way to fast plus the jump just teleports you into the air and going backwards sometimes shoots me into the air and the last thing
    I have 999+ errors now in my console I NEED HELP

    using UnityEngine;
    using System.Collections;

    public class PlayerMovment : MonoBehaviour {

    public float playerSpeed;
    public float sprintSpeed = 2f;
    public float walkSpeed = 1f;
    public float mouseSensitivity = 2f;
    public float jumpHeight = 3f;
    private bool isMoving = false;
    private bool isSprinting =false;
    private float yRot;

    private Animator anim;
    private Rigidbody rigidBody;

    // Use this for initialization
    void Start () {

    playerSpeed = walkSpeed;
    anim = GetComponent<Animator>();
    rigidBody = GetComponent<Rigidbody>();

    }

    // Update is called once per frame
    void Update () {

    yRot += Input.GetAxis("Mouse X") * mouseSensitivity;
    transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, yRot, transform.localEulerAngles.z);

    isMoving = false;

    if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
    {
    //transform.Translate(Vector3.right * Input.GetAxis("Horizontal") * playerSpeed);
    rigidBody.velocity += transform.right * Input.GetAxisRaw("Horizontal") * playerSpeed;
    isMoving = true;
    }
    if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
    {
    //transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * playerSpeed);
    rigidBody.velocity += transform.forward * Input.GetAxisRaw("Vertical") * playerSpeed;
    isMoving = true;
    }

    if (Input.GetKeyDown(KeyCode.Space))
    {
    transform.Translate(Vector3.up * jumpHeight);
    }

    if (Input.GetAxisRaw("Sprint") > 0f)
    {
    playerSpeed = sprintSpeed;
    isSprinting = true;
    }else if (Input.GetAxisRaw("Sprint") < 1f)
    {
    playerSpeed = walkSpeed;
    isSprinting = false;
    }

    anim.SetBool("isMoving", isMoving);
    anim.SetBool("isSprinting", isSprinting);

    }
    }
     
  2. Peeling

    Peeling

    Joined:
    Nov 10, 2013
    Posts:
    404
    Please edit your post and use the <> code button to make your script readable. Then I can take a look!
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,964
    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    You may edit your post above.

    If you have absolutely no idea what is happening, here is how to change that:

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.
     
  4. hofnergluke

    hofnergluke

    Joined:
    Apr 28, 2022
    Posts:
    3
    okay well I didn't see this until I fixed it myself but thanks for replying anyway
     
  5. hofnergluke

    hofnergluke

    Joined:
    Apr 28, 2022
    Posts:
    3
    although I now have a sliding problem that I don't know how to fix
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Kurt-Dekker likes this.