I’m new to unity and I am trying to make a platformer. I have a controller but it is very odd and the jumping is all wack can someone please help change my code to make it better?
here is my code:
using UnityEngine;
using System.Collections;
public class AlienController : MonoBehaviour
{
public float maxSpeed = 10f;
public float jumpForce = 700f;
Rigidbody2D rb;
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
// Use this for initialization
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
Debug.Log(grounded);
float move = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(move * maxSpeed, rb.velocity.y);
}
void Update()
{
if (grounded && Input.GetAxis("Jump") > 0)
{
rb.AddForce(new Vector2(0, jumpForce));
}
}
}