- Home /
How do I make ray cast to detect land?
I'm trying detect the land before the player in 2d game so that it can alert. Ray should be front and downside so that player can see the land. How can I make the direction this way? Any ideas?
Answer by Anxo · Jan 17, 2013 at 12:59 AM
Yes, Type Raycast in the Scripting Reference and you will find how to do exactly that. Cast a ray down before an object hits the floor.
So for down direction we have to make var fwd = transform.TransformDirection (0,-1,0);? as y -1?
sounds right. did not look into it but yes. Y is your up and down so -1 sounds right.
But that is only if your character's down ever changes. Otherwise you can just not make a fwd var and just always have it pointing in world down.
I'm trying to do forward direction and downwards, taking var fwd = transform.TransformDirection (1,-0.5,0); to get the angle, but it's not working.
oh. Well that all depends on which way you your character is orientated in the world, and within its own transform. What you can do is put an empty game object inside your characters game object. Name it something like downForwardDirection. Rotate the empty game object so that it's Z axis points in the direction you want the ray to fire or what ever. Then say fwd = downForwardDriection.transform.TransformDirection(0.0.1);
Your answer
Follow this Question
Related Questions
My Raycasts seem to sometimes miss 0 Answers
onGround raycasts return onGround is true while colliding with platform sides 0 Answers
Object following a path and colliding with other objects with physics. 1 Answer
How to use `Physics2D.IgnoreCollision()` to implement a one-way platform? 0 Answers
Moving a player smoothly without breaking collisions? 2 Answers