- Home /
Why is the sphere falling through the platform?
I don't want to use physics I'm just testing out something. I have a sphere and you can move left and right with it and I also have a gravity force making it fall down. But when it falls it goes straight through the platform underneath. both the platform and the sphere have colliders. it lands on the platform when i give the sphere a rigidbody but I don't want to use a rigidbody. How do I do it this way so the sphere will land on the platform and why is it falling through the platform?
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
Vector2 dir;
int gravity = 2;
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.A))
{
dir.x = -5;
}
else if (Input.GetKey(KeyCode.D))
{
dir.x = 5;
}
else
dir.x = 0;
dir.y -= gravity * Time.smoothDeltaTime;
transform.Translate(dir * Time.smoothDeltaTime);
}
}
EDIT: As I said below Don't let the image put you off. it's just of an image of the sphere at the moment of impact with the platform. It starts out much higher up and falls toward the platform and then falls through.
Answer by Hoeloe · May 23, 2013 at 05:11 PM
Collisions are not detected unless at least one object has a rigidbody. You can, however, disable just about every feature of the rigidbody other than this to allow it to work how you like.
Ok, Thanks a lot. Guess I need to use rigidbodies after all.
Answer by Stormizin · May 23, 2013 at 04:47 PM
Try to put the sphere a lil bit height from the platform
oh, Don't let the image put you off. it's just of an image of the sphere at the moment of impact with the platform. It starts out much higher up and falls toward the platform and then falls through.
Check if the Is Trigger checkbox is checked. I got an error like this too. Solved with code.
Your answer
Follow this Question
Related Questions
Constant force, with gravity, and correct collisions. 2 Answers
How do you modify gravity force in this script ? 1 Answer
Check if Rigidbody collider is grounded 3 Answers
How do you change the direction of gravity? 1 Answer
Why does my characterController code not apply gravity correctly? 0 Answers