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
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;
}
}
}