2D Android Game Rapid Jumping Problem,Unity 2018.2.9f1 Android 2d Speed Jumping
I am working on creating 2D Android Game but have the problem with jumping. Character jumps rapidly. I want to make a slower jump. I actually didn't see when the jumping began. Does anyone help me with this issue?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class CatControl : MonoBehaviour {
float dirX;
public float moveSpeed = 5f;
Rigidbody2D rb;
bool facingRight = true;
Vector3 localScale;
float jumpForce = 600f;
// Use this for initialization
void Start () {
localScale = transform.localScale;
rb = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
dirX = CrossPlatformInputManager.GetAxis ("Horizontal");
if (CrossPlatformInputManager.GetButtonDown("Jump"))
Jump();
}
void FixedUpdate()
{
rb.velocity = new Vector2 (dirX * moveSpeed, 0);
}
void LateUpdate()
{
CheckWhereToFace ();
}
void CheckWhereToFace ()
{
if (dirX > 0)
facingRight = true;
else if (dirX < 0)
facingRight = false;
if (((facingRight) && (localScale.x < 0)) || ((!facingRight) && (localScale.x > 0)))
localScale.x *= -1;
transform.localScale = localScale;
}
void Jump()
{
if (rb.velocity.y == 0)
rb.AddForce(Vector3.up * jumpForce * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
How do I turn off the previous object? 1 Answer
[2D] Slide object after collision 2 Answers
top down 2d shooter direction of enemies 0 Answers
Unity 2d Collision Glitch Help 0 Answers