How do I add a jump mechanic to my script?
All the transform components of my player script work and my camera script also follows the player, but I’m not sure how to implement jumping into the script so it can work with my animation states.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
[SerializeField] private float speed = 2f;
[SerializeField] private float turnSpeed = 45f;
[SerializeField] private float rotationSpeed;
private Animator animator;
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
var velocity = Vector3.forward * Input.GetAxis("Vertical") * speed;
transform.Translate(velocity * Time.deltaTime);
transform.Rotate(Vector3.up, Input.GetAxis("Horizontal") * Time.deltaTime * turnSpeed);
animator.SetFloat("Speed", velocity.z);
}
}