- Home /
Find intersection (with Picture)
it's a math question. i couldn't form it as text, so i made a picture
Answer by nesis · Jan 15, 2014 at 03:13 PM
If the black line is pointing the same direction that the player is facing, you can make a script and attach it to the player's GameObject, and in that script, you can use transform.forward
to get the direction the player is facing.
In the C# code, you'd write it as:
Ray ray = new Ray(transform.position,transform.forward);
RaycastHit hit;
if (Physics.Raycast(ray,out hit,Mathf.Infinity)) {
//if an object with a collider was hit by the ray, Physics.Raycast() will return true
//the "hit" variable now contains information about what
//the raycast intersected with first - look at the
//documentation for Physics.Raycast for more info:
//http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
}
thanks, i chose RaycastHit.point and it works fantastically
Answer by timcommandeur · Jan 15, 2014 at 03:18 PM
This might be a hacky solution. But I would use raycasting with a ray thats bellow the player and parallel to the players rotation. Then change the position.y of the hit info to the max bound y of the cube. The ray in this case would start inside the cube the player's standing on so I'm not sure if it will think it's colliding with the current cube the players on. To solve this you could use raycastall and ignore the first hit. Hope this helps.
Unity works with convex colliders, it only checks if you're going from outside to inside a collider. This means that if a raycast starts inside a box collider, there's no way you'll get a collision with that same box.
superlevani, it'd be good if you could clear up what exactly you're wanting, even if you're unsure of the ter$$anonymous$$ology. On closer inspection, it seems like you're wanting the black line to be following the same horizontal forward direction of the player, but rotated so it sits exactly on the top edge of the cube?
thanks for answer, but nesis's answer was better, so i chose it as accepted
Your answer
Follow this Question
Related Questions
Positions to rotations of a regular GO 2 Answers
Calcultate spawn position based on spawn volume's rotation 2 Answers
Making an enemy face the Player 0 Answers
Rotate Center Pivot based Object like a Draw Bridge 2 Answers
Mathf.Lerp not working 2 Answers