Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Trying to have a ball that rolls using addForce to have a raycast to detect if the ground is underneath it.

$
0
0
Hey, guys, I am trying to make a ball that is rolling in a 2d space detect whether it is on the ground or not for making the ball only jump when it is on the ground. I am currently only having trouble figuring out the ground detection.

            RaycastHit Hit;
            float Distance;
            Vector2 up = transform.TransformDirection(-Vector2.up) * 10;
            Debug.DrawRay(transform.position, up, Color.green);
            if (Physics.Raycast(transform.position, (up), out Hit))
            {
                Distance = Hit.distance;
                print(" "+ Distance + " " + Hit.collider.gameObject.name + " ");
            }
This is currently what I'm using, but the raycast rolls with the ball instead of staying pointed at the ground. Any assistance would be greatly appreciated!

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>