Answer the question
In order to leave comments, you need to log in
How to make a jump?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private Rigidbody _rigidbody;
public FixedJoystick joystick;
public Transform groundCheck;
public LayerMask groundMask;
public float playerspeedRL = 5f;
private float gravity = -9.81f;
public float radius = 0.72f;
bool isGrounded;
Vector3 velocity;
void Start()
{
_rigidbody = GetComponent<Rigidbody>();
}
void Update()
{
}
void FixedUpdate()
{
isGrounded = Physics.CheckSphere(groundCheck.position, radius, groundMask);
if (isGrounded)
{
_rigidbody.velocity = new Vector3(5 * joystick.Direction.x, 0, 5);
//_rigidbody.velocity = transform.forward * 5 + transform.right * joystick.Direction.x * playerspeedRL;
}
else
{
_rigidbody.velocity = new Vector3(5 * joystick.Direction.x, gravity, 5);
//_rigidbody.velocity = transform.forward * 5 + transform.right * joystick.Direction.x * playerspeedRL + transform.up * gravity;
}
}
public void JumpScript()
{
if (isGrounded)
{
_rigidbody.velocity = new Vector3(0, 30, 0);
//_rigidbody.velocity = transform.up * 30;
Debug.Log("Jump");
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question