I have an issue where when a ball sprite isn’t rolling it will jump as I expect it to; however, when I have the ball rolling, it doesn’t fall properly or reach the height is should be. Here is my script,
using UnityEngine;
using System.Collections;
public class BallController : MonoBehaviour {
Vector3 pos;
float posSmooth = 1.0f;
float rotSmooth = 0.318f;
public bool rollingEnabled = true;
public Rigidbody2D rb;
public GameObject sprite;
float thrust = 600f;
Vector2 zero = new Vector2(0f, 0f);
bool jumping = false;
// Use this for initialization
void Start ()
{
pos = transform.position;
}
// Update is called once per frame
void Update ()
{
if(Input.GetKeyDown (KeyCode.Space))
{
jumping = true;
}
}
void FixedUpdate ()
{
if(jumping)
{
jumping = false;
rb.velocity = zero;
rb.AddForce (transform.up * thrust);
}
if(rollingEnabled)
{
pos.x += posSmooth * Time.deltaTime;
transform.position = pos;
sprite.transform.Rotate (Vector3.back, 180.0f * Time.deltaTime * rotSmooth, Space.Self);
}
}
}
I thought it might be an issue with Update or FixedUpdate interfering with the other, but after setting my code up like I probably should’ve in the first place, nothing change.