UnityNinja Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

UnityNinja CommunityLog in

UnityNinja - Video Game Development Community, including Resources, Forums, Marketplace & More.


descriptionLooking for help with the movement Script  EmptyLooking for help with the movement Script

more_horiz
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

descriptionLooking for help with the movement Script  EmptyRe: Looking for help with the movement Script

more_horiz
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);
    }
}
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply