using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class character : MonoBehaviour
{
public float speed = 6.0f;
public float rotateSpeed = 6.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
private Animator anim;
private Vector3 moveDirection = Vector3.zero;
private CharacterController controller;
private int jumps;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if (controller.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if(Input.GetButtonDown("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("Jumping");
anim.SetBool("IamJumping", true);
}
}
}
I have an problem i want my character to kind of fly so you can jump high and you almost have no gravity and then we can shoot each other with fireballs and the ground is lava with some cubes you can stand on.
Maybe later when im better at coding i can make the character fly with a cooldown and more abilities you can pick up.
But i have one problem in the code when the character asset: devil animated character ( is free btw )
is in the air i want it to play the flying animation so when i press jump it plays it but that is also the problem
because it only plays it 1 second how do i make the animation play when my character is in the air? Is this even possible …