So I am trying to make a platformer right and i followed a lot of tutorials but mostly this one : Recorded Video Sessions on 2D in Unity 4.3 - Unity Learn . With it I learned a lot of things and i can make my character run and jump now, but id like to know if there is a way to set a particular jump distance so it can be more precise and controllabe. Here is the script : PlayerControllerScript
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControllerAstronaut : MonoBehaviour {
public float maxSpeed = 10f;
bool facingRight = true;
Animator anim;
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
public float jumpForce = 700;
void Start () {
anim = GetComponent();
}
void FixedUpdate () {
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
anim.SetBool(āGroundā, grounded);
anim.SetFloat(āvSpeedā, GetComponent().velocity.y);
if (!grounded) return;
float move = Input.GetAxis(āHorizontalā);
anim.SetFloat(āSpeedā, Mathf.Abs(move));
GetComponent().velocity = new Vector2 (move * maxSpeed, GetComponent().velocity.y);
if (move > 0 && !facingRight)
Flip();
else if (move < 0 && facingRight)
Flip();
}
void Update ()
{
if(grounded && Input.GetKeyDown(KeyCode.Space))
{
anim.SetBool(āGroundā, false);
GetComponent().AddForce(new Vector2(0, jumpForce));
}
}
void Flip ()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
I am new so most of this stuff can seems easy to do but i dont know how to do it
I tried to set it up myself but it still didnt work out.
P.S.
My character sometimes trip on the ground and fall making him strange to control since he is moving on his back/belly depending on which side i move him. I dont know how to fix this but I think its because of the colliders, maybe ?