I’m trying to make a 2D ball physics puzzle game. Where the player controls a ball through a maze type thing.
When I make the ball jump, It sometimes jumps really high, and sometimes it barely gets off the floor.
Here is the code I am using, It is attached to the ball:
using UnityEngine;
using System.Collections;
public class Control : MonoBehaviour {
public GameObject Ball;
public float JumpSpeed;
public Camera cam;
public float runSpeed;
// Use this for initialization
void Start () {
Time.timeScale = 5.0f;
}
// Update is called once per frame
void Update () {
}
void FixedUpdate () {
// Jumping code:
if (Input.GetButtonDown ("Jump") ) {
Ball.rigidbody.AddForce (Vector3.up * JumpSpeed);
}
Ball.rigidbody.AddForce (-Vector3.left * (Input.GetAxis("Horizontal") * runSpeed));
float camToX = Ball.transform.position.x;
float camToY = Ball.transform.position.y;
float camToZ = cam.transform.position.z;
Vector3 moveCamTo = new Vector3(camToX,camToY, camToZ);
cam.transform.position = moveCamTo;
}
}
Any help would be Greatly Appreciated!
Also, If any one could help my with not double/multi jumping would be nice too but it isn’t needed