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.
Instead of modyfing velocity directly, you might want to use rigidbody.AddForce or AddForceAtPoint. That will take care of your first problem.
– EvilTakIf I use rigidbody.AddForce I can't know after how many seconds my sphere covers #x units. My "0" problem is that I need to know where my sphere, in each seconds, will be in the x axis. With rigidbody.AddForce the speed is not constant . . .
– RobyRothen