Hi everybody, I searched a lot but I didn’t find a solution to my problems.
I have a sphere. I want that this sphere jumps after “x” seconds of a timer.
I did it but I have 2 problems.
First problem:
Trying to understand which is the relation from “second” to “distance” (i.e. after how many seconds the sphere covers 4x unit??) I did a few attempts:
-
rigidbody.velocity = new Vector3 (2,0,0);
The sphere rotates BUT the gravity doesn’t work and the jump is not natural.
-
transform.position += Vector3.right * speed * Time.deltaTime;
The gravity and the jump are perfect BUT the sphere instead of rotating, crawls.
Second problem:
About the “groundcheck”, I wrote this code:
public bool isJumping = false;
void FixedUpdate ()
{
//stuff
if(myCondition)
{
//rigidbody.velocity = new Vector3 (2,0,0);
//transform.position += Vector3.right * speed * Time.deltaTime;
if (myCondition && isJumping == false)
{
rigidbody.velocity = new Vector3 (0,5,0); //
isJumping = true;
}
}
}
void OnCollisionEnter(Collision col)
{
if(col.gameObject.tag == "Ground")
{
isJumping = false;
}
}
}
What happens is this:
IF #1: The sphere jumps and then, in the air, tries to jump again → doesn’t jump (perfect!)
IF #2: The sphere is falling, tries to jump → jump . . . How can I fix this?
I already sat the tag “Ground” to my ground.
I hope you understand my problems (despite my english) and somebody are able to tell me the solutions.
thanks, bye.