- Home /
 
 
               Question by 
               John-155 · Nov 28, 2018 at 06:09 AM · 
                jumpjumping objectforcemode  
              
 
              how to make a realistic jump? Very urgent please :(
 /*
 I have a script in which there is a part of the code responsible for the jump, but when I try to jump my object, the ball jumps not naturally and too slowly or too quickly, high or low. I am interested in how to implement a more realistic jump. Thanks in advance.
 */
 
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BallController : MonoBehaviour {
 public float speed;
 public float fast = 2f;
 float LR;
 Vector3 coordinats;
 public float magnitude = 2f;
 public Rigidbody RB;
 public float jump;
 public bool ground;
 public float speed_ball = 15f;
 
 private void Update()
 {
 Ray ray = new Ray(RB.transform.position, Vector3.down);
 RaycastHit rh;
 if (Physics.Raycast(ray, out rh, 0.8f))
 {
 ground = true;
 }
 else
 {
 ground = false;
 }
 if ((Input.touchCount > 0) && (ground == true))
 {
 //RB.AddForce(Vector3.zero);
 RB.AddForce(Vector3.up * jump, ForceMode.VelocityChange); // JUMP UP
 }
 if ((ground == false) && RB.transform.position.y > 1f)
 {
 //RB.AddForce(Vector3.zero);
 RB.AddForce(-Vector3.up * jump, ForceMode.Impulse); // I GIVE THE OBJECT A REVERSE IMPULSE
 
 /////////
 
 GetComponent().AddForce(Vector3.forward * fast, ForceMode.Acceleration);
 coordinats = Input.acceleration; // сохраняет данные акселерометра в переменную
 if (coordinats.sqrMagnitude > magnitude){
 coordinats.Normalize();
 }
 coordinats.Normalize();
 
 if (coordinats.x > 0.1f)
 {LR = 0.15f; transform.Translate(new Vector3(LR * speed * Time.deltaTime, 0, 0));} // поворачивает враво
 if (coordinats.x < -0.1f)
 { LR = -0.15f; transform.Translate(new Vector3(LR * speed * Time.deltaTime, 0, 0)); } // поворачивает влево
 }
 
 private void Start()
 {
 RB = GetComponent();
 RB.AddForce(Vector3.forward * 5f, ForceMode.Impulse); // дает толчок шарику при старте
 }
 }
 
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Jumping only once (2D) 2 Answers
player jump on UI button release 1 Answer
I have a problem with my jump script 1 Answer
change multiple jump to single jump 1 Answer
jump and check ground problem! 2 Answers