Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » General Dicussions » Looking for help with the movement Script

Looking for help with the movement Script

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Looking for help with the movement Script on Tue Jul 05, 2016 4:03 pm

Garzec


Member [Lv. 2]
Member [Lv. 2]
Hi,

i just made a post here, i hope someone would like to help me out Smile

http://armedunity.com/topic/13954-looking-for-help-with-the-movement-script/

That would be really awesome

View user profile

Garzec


Member [Lv. 2]
Member [Lv. 2]
i just translated the script into english Smile

Code:

public class zTESTTESTTEST : MonoBehaviour
{
    // movementspeed
    public float movementSpeed = 12f;

    // horizontal rotationspeed
    public float rotationSpeed = 1.7f;

    // jump velocity
    private float verticalJumpVelocity = 0;

    // jump speed
    public float jumpSpeed = 15.0f;

    // gravity
    public float gravity = 30.0f;

    // CharacterController
    private CharacterController controller;

    // movement velocity
    private Vector3 movementVelocity = Vector3.zero;

    // players head
    public Transform head;

    // vertical rotationspeed
    private float rotationSpeedVertical = 0.5f;

    // max head turn vertical
    public float maxTurnHeadVertical = 20.0f;

    // min head turn vertical
    public float minTurnHeadVertical = -20.0f;

    // current head turn
    private float currentHeadTurn = 0;

    // can double jump ?
    bool canDoubleJump = false;

    // initialising
    private void Start()
    {
        // controller
        controller = GetComponent<CharacterController>();
    }

    // per frame
    private void Update()
    {
        // rotation inputs
        Vector2 rotationVector = new Vector2(Input.GetAxis("RightJoystickHorizontal"), -Input.GetAxis("RightJoystickVertical"));

        // ground check
        if (controller.isGrounded)
        {
            // move player
            movementVelocity = transform.TransformDirection(new Vector3(Input.GetAxisRaw("LeftJoystickHorizontal"), 0, -Input.GetAxisRaw("LeftJoystickVertical"))) * movementSpeed;
            // dont move in the air
            verticalJumpVelocity = 0;
            // jump
            if (Input.GetButtonDown("XButton"))
            {
                // jump speed
                verticalJumpVelocity = jumpSpeed;
                // can double jump
                canDoubleJump = true;
            }
        }
        // player in the air
        else if (!controller.isGrounded)
        {
            // double jump
            if (Input.GetButtonDown("XButton") && canDoubleJump)
            {
                // jump speed
                verticalJumpVelocity = jumpSpeed;
                // no double jump
                canDoubleJump = false;
            }
        }

        // rotate head vertical
        currentHeadTurn = Mathf.Clamp(currentHeadTurn + rotationVector.y * rotationSpeedVertical, minTurnHeadVertical, maxTurnHeadVertical);
        head.localRotation = Quaternion.identity;
        head.Rotate(Vector3.left, currentHeadTurn);

        // gravity on moving
        verticalJumpVelocity -= gravity * Time.deltaTime;

        // rotate player
        transform.Rotate(Vector3.up, rotationVector.x * rotationSpeed);

        // movement + vertical movement
        Vector3 beschleunigung = movementVelocity + verticalJumpVelocity * Vector3.up;

        // move player
        controller.Move(beschleunigung * Time.deltaTime);
    }
}

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum