In my Script i'm using a jump Force, the reason being is because i don't know any other way of jumping. So sometimes when the Object Jumps it lowers its jump height when i move, any way of going around this? this is my code Code (CSharp): using UnityEngine; using System.Collections; public class SimpleController : MonoBehaviour { [HideInInspector] public bool jump = false; public float Speed = 0f; public Transform groundCheck; public float JumpForce; private float move = 0f; private bool grounded = false; private Rigidbody2D rb2d; void Awake () { rb2d = GetComponent<Rigidbody2D>(); } void Update () { grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground")); transform.eulerAngles=new Vector3(0,transform.eulerAngles.x,transform.eulerAngles.y); // Lock Rotations if(grounded) { jump = true; } } void FixedUpdate () { move = Input.GetAxis ("Horizontal"); GetComponent<Rigidbody2D>().velocity = new Vector2 (move * Speed, GetComponent<Rigidbody2D>().velocity.y); if (jump) { rb2d.AddForce (new Vector2 (rb2d.velocity.x,JumpForce)); jump = false; } } }
It's problem with addforce, the longer your Physic2D linecast check the layermask, the bigger jump force, when u move your player, time check will be shorter and the force is lower. u can jump by add the velocity directly to your player like : this.rigidbody.velocity=new Vector2();
I would avoid using Physics for platforming. It's somewhat hard to get it to do what you want it to. But there is a great tutorial for a simple and effective platforming system here: https://www.youtube.com/playlist?list=PLFt_AvWsXl0f0hqURlhyIoAabKPgRsqjz With this tutorials, system you set the jump height and jump duration which is a bit more intuitive for designing a game.