So I have this script, shown below:
`
var moveSpeed : float = 0.1;
private var IsGrounded = false;
var JumpStrength : float = 5;
private var animator;
function Start() {
animator = GetComponent("Animator");
}
function Update () {
gameObject.transform.Translate(Input.GetAxis("Horizontal") * moveSpeed, 0, 0);
if(Input.GetKey("a")) {
gameObject.transform.localScale.x = -1;
}else if( Input.GetKey("d") ){
gameObject.transform.localScale.x = 1;
}
if(Input.GetKey("a") || Input.GetKey("d")) {
animator.SetBool("running", true);
}else{
animator.SetBool("running", false);
}
if(Input.GetKeyDown("space") && IsGrounded) {
IsGrounded = false;
Jump();
}
}
function OnCollisionEnter2D(col : Collision2D) {
if(col.gameObject.tag == "Ground")
IsGrounded = true;
}
function Jump() {
IsGrounded = false;
gameObject.rigidbody2D.AddForce(Vector2.up * JumpStrength);
IsGrounded = false;
}
and whenever I hold either the A or D keys, and press space, I have the ability to double jump, which is not intended and is rather overpowered to add to my game. I assume there's something wrong with
gameObject.transform.Translate(Input.GetAxis(“Horizontal”) * moveSpeed, 0, 0);
`
that doesn’t like collisions. Is there any workaround or solution?