Answer the question
In order to leave comments, you need to log in
What is wrong with the jump implementation?
So, I'm a macro, I could not find a ready-made button in the assets store, and decided to improvise, I created a button on the screen, and gave it the name "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 = transform.forward * 5 + transform.right * joystick.Direction.x * playerspeedRL;
}
else
{
_rigidbody.velocity = transform.forward * 5 + transform.right * joystick.Direction.x * playerspeedRL + transform.up * gravity;
}
//_rigidbody.velocity = transform.forward * 5 + transform.right * joystick.Direction.x * playerspeedRL + transform.up * gravity;
}
public void JumpScript()
{
if (Input.GetButtonDown("Jump") && isGrounded)
{
_rigidbody.velocity = transform.up * 30;
Debug.Log("Jump");
}
}
}
Answer the question
In order to leave comments, you need to log in
In the inspector, the button has a OnClick
drag-and-drop component on which you will call the method, and then you will select it there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question