using UnityEngine;
using System.Collections;
public class Lcircle : MonoBehaviour {
public float Ballspeed = 1F;
public Vector3 playerPos;
void Update () {
float xPos = gameObject.transform.position.x + (Input.GetAxis ("Horizontal") * Ballspeed);
playerPos = new Vector3 (Mathf.Clamp(xPos, -7, -1), -3, 0);
gameObject.transform.position = playerPos;
}
}
You could use the Vector3.Lerp() function to lerp between the ground y-value and the y-value of the highest point in your jump and then the other way around. But that won’t give the most realistic effect. You could also use unity physics and put a velocity on your ball’s y-axis.
Or, like I just did in the game I am currently writing, you can use a coroutine function for jumping
private float m_JumpSpeed = 10f;
private IEnumerator Jump()
{
float gravity = -Physics.gravity.y;
float jumpVelocity = m_JumpSpeed;
float initialY = transform.position.y;
while (transform.position.y >= initialY)
{
transform.Translate(0f, jumpVelocity * Time.deltaTime, 0f);
jumpVelocity -= gravity;
yield return null;
}
transform.position = new Vector3(transform.position.x, initialY, transform.position.z);
}