0% found this document useful (0 votes)
20 views2 pages

MOVIMIENTO

The document contains a Unity C# script for character movement without object interaction. It includes functionalities for player movement, jumping, and camera control based on mouse input. Key parameters such as speed, jump force, and sensitivity are adjustable via the Unity Inspector.

Uploaded by

gomez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

MOVIMIENTO

The document contains a Unity C# script for character movement without object interaction. It includes functionalities for player movement, jumping, and camera control based on mouse input. Key parameters such as speed, jump force, and sensitivity are adjustable via the Unity Inspector.

Uploaded by

gomez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

// MOVERSE SIN INTERACION DE OBJETOS //CHARACTER CHONTROLLER

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

public class MOVIMIENTO : MonoBehaviour

{
private Vector3 playerMovementInput;
private Vector2 playerMouseInput;
private Vector3 velocity;
private float xRot;
[SerializeField] private Transform playerCamera;
[SerializeField] private CharacterController controller;
[Space]
[Space]
[Range(0, 12f)][SerializeField] private float speed=4;
[Range(0, 12f)][SerializeField] private float jumpForce=10;
[Range(0, 12f)][SerializeField] private float sensitivity=3;
[Space]
[SerializeField] private float gravity = -9.81f;

private void Start()


{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
playerMovementInput = new Vector3(Input.GetAxis("Horizontal"), 0f,
Input.GetAxis("Vertical"));
playerMouseInput = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

MovePlayer();
MovePlayerCamera();
}
private void MovePlayer()
{
Vector3 MoveVector = transform.TransformDirection(playerMovementInput);

if (controller.isGrounded)
{
velocity.y = -1f;
if (Input.GetKeyDown(KeyCode.Space))
{
velocity.y = jumpForce;
}
}

else
{
velocity.y -= gravity * -2f * Time.deltaTime;
}
controller.Move(MoveVector * speed * Time.deltaTime);
controller.Move(velocity * Time.deltaTime);
}
private void MovePlayerCamera()
{
xRot -= playerMouseInput.y * sensitivity;
transform.Rotate(0f, playerMouseInput.x * sensitivity, 0f);
playerCamera.transform.localRotation = Quaternion.Euler(xRot, 0f, 0f);
}
}

You might also like