This question was
closed Sep 10, 2018 at 07:13 AM by
tormentoarmagedoom for the following reason:
Too subjective and argumentative
Question by
ThePhantomGoat · Sep 09, 2018 at 01:40 AM ·
jumpjumpinginfinite
Player Is infinite jumping
hi, just a simple question from a noob, how do I get this to stop jumping infinitely?
using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour {
[HideInInspector]
public bool isFacingRight = true;
[HideInInspector]
public bool isJumping = false;
[HideInInspector]
public bool isGrounded = false;
public GameObject thing;
public GameObject floor;
public GameObject platform;
public float maxSpeed = 7.0f;
public float jumpForce = 650.0f;
public Transform groundCheck;
public LayerMask groundLayers;
private float groundCheckRadius = 0.2f;
void Start()
{ }
void Update()
{
if (Input.GetButtonDown("Jump"))
{
if (isGrounded == true)
{
this.GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, 0);
this.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpForce));
}
if (floor == thing)
{
this.GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, 0);
this.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpForce));
}
}
}
void FixedUpdate()
{
isGrounded = Physics2D.OverlapCircle
(groundCheck.position, groundCheckRadius, groundLayers);
float move = Input.GetAxis("Horizontal");
this.GetComponent<Rigidbody2D>().velocity =
new Vector2(move * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);
if ((move > 0.0f && isFacingRight == false) || (move < 0.0f && isFacingRight == true))
{
Flip();
}
}
void Flip()
{
isFacingRight = !isFacingRight;
Vector3 playerScale = transform.localScale;
playerScale.x = playerScale.x * -1;
transform.localScale = playerScale;
}
}
Comment
Best Answer
Answer by tormentoarmagedoom · Sep 10, 2018 at 07:13 AM
Good day.
Thats not a question, you are asking to do the job for you. If you are not able to understand what this code does, go look at google for each variable and function, 1 by 1.
We are not code providers.
Bye!