He will move the left 4 or so units whenever you press jump, then back to the original position.
Code (including the rest of the controller because I don’t know if it is mixed up somewhere in the rest)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bobcontroller : MonoBehaviour {
public float maxSpeed = 10f;
bool facingRight = true;
bool ground = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
public float jumpForce = 700f;
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
if (ground && Input.GetKeyDown(KeyCode.Space))
{
anim.SetBool("Ground", false);
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpForce));
}
}
void FixedUpdate () {
{
ground = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
anim.SetBool("Ground", ground);
anim.SetFloat ("vSpeed", GetComponent<Rigidbody2D>().velocity.y);
float move = Input.GetAxis("Horizontal");
anim.SetFloat("Speed", Mathf.Abs(move));
GetComponent<Rigidbody2D>().velocity = new Vector2(move * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);
if (move > 0 && !facingRight)
Flip();
else if (move < 0 && facingRight)
Flip();
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
I’m very new to programming so sorry if the issue is glaringly obvious… Thanks in advance!!