- Home /
Question by
Gamers_IDentity1 · Apr 14 at 01:38 PM ·
scripting problem3dmovement scriptcharacter controller
How can i make my character jump and slide on command?
I am making an endless runner and i want to make my character jump and slide on command Space and shift. The animations are already assigned please someone modify the code so i can make my character controller jump and slide. I have seen numerous tutorials on youtube and unable to figure out what is going wrong.
The game is 3D.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class PlayerMove : MonoBehaviour
{
public float moveSpeed = 3;
public float leftRightSpeed = 4;
public Animator anim;
void Update()
{
transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed, Space.World);
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
if (this.gameObject.transform.position.x > LevelBoundary.leftSide)
{
transform.Translate(Vector3.left * Time.deltaTime * leftRightSpeed);
}
}
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
if (this.gameObject.transform.position.x < LevelBoundary.rightSide)
{
transform.Translate(Vector3.left * Time.deltaTime * leftRightSpeed * -1);
}
}
if(Input.GetKeyDown(KeyCode.Space))
{
anim.SetBool("Jump", true);
}
else
anim.SetBool("Jump", false);
if(Input.GetKey(KeyCode.LeftShift))
{
anim.SetBool("Slide", true);
}
else
anim.SetBool("Slide", false);
}
}
Comment
Your answer
Follow this Question
Related Questions
How do i maintain the same speed in the air? 1 Answer
3D Movement but the player can only move backwards (Beginner) 1 Answer
Movement Code not working 2 Answers
How to make a 3rd person character controller 0 Answers
How to minimize an input value? 0 Answers