- Home /
 
 
               Question by 
               CODeboiidk · May 16 at 07:04 PM · 
                c#movementunityeditor  
              
 
              Any way I can add rolling to this movement script that is similar to dark souls?
The script is:
using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Security.Cryptography; using System.Threading; using UnityEngine;
public class ThirdPersonMovement : MonoBehaviour {
 void Start()
 {
     Cursor.lockState = CursorLockMode.Locked;
 }
 public CharacterController controller;
 public Transform cam;
 public float speed = 6;
 public float gravity = -9.81f; 
 public float jumpHeight = 3;
 Vector3 velocity;
 bool isGrounded;
 public Transform groundCheck;
 public float groundDistance = 0.4f;
 public LayerMask groundMask;
 float turnSmoothVelocity;
 public float turnSmoothTime = 0.1f;
 public float RunSpeed;
 public float NormalSpeed;
 public bool isRunning = false;
 // Update is called once per frame
 void Update()
 {
     //jump
     isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
     if (isGrounded && velocity.y < 0)
     {
         velocity.y = -2f;
     }
     if (Input.GetButtonDown("Jump") && isGrounded)
     {
         velocity.y = Mathf.Sqrt(jumpHeight * -2 * gravity);
     }
     if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift) && isGrounded)
     {
         isRunning = true;
         speed = RunSpeed;
     }
     else
     {
         isRunning = false;
         speed = NormalSpeed;
         //gravity
         velocity.y += gravity * Time.deltaTime;
     }
     controller.Move(velocity * Time.deltaTime);
     //walk
     float horizontal = Input.GetAxisRaw("Horizontal");
     float vertical = Input.GetAxisRaw("Vertical");
     Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
     if (direction.magnitude >= 0.1f)
     {
         float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
         float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
         transform.rotation = Quaternion.Euler(0f, angle, 0f);
         Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
         controller.Move(moveDir.normalized * speed * Time.deltaTime);
     }
 }
 
               }
Also any other advice on movement like how to make the run feel more natural (like with a build up to full speed) or wall-running, etc would be appreciated
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Distribute terrain in zones 3 Answers
How do I stop the player from gliding while in the air? 1 Answer
Multiple Cars not working 1 Answer
Basic Movement Problems 1 Answer