- Home /
Raycast constant v shape in front of player on any rotation
Hey guys so I need to make a raycast with constant v shape in front of player and so that it raycast horizontally and doesn't intersect with player(just like in pic 1 but on any rotation, I need to place hands according to those rays). Problem is that whenever I turn the player rays do not turn with it(I make rays out of the child empty object).
Code:
Physics.Raycast(IKRayOrigin.transform.position + originOffset, -IKRayOrigin.transform.up + leftVector, out L_hit, ledgeScript.grabHeight)
Physics.Raycast(IKRayOrigin.transform.position + originOffset, -IKRayOrigin.transform.up + rightVector, out R_hit, ledgeScript.grabHeight)
Ray Offset values:
left vector: x: -0.47ff y:0f z:0.23
right vector 0.35f,0,0.23
Empty game object(origin local position): -0.108,2.03,0.366
Answer by Duckocide · Oct 26, 2020 at 10:49 AM
I'm assuming the blue diamond / cube is attached as a child to the character.
If so a really quick way of getting the right direction out of the blue diamond / cube is to add two empty game objects in turn to it. Orientate those objects transforms so the z-axis (blue) is point the way you want each ray to go. Then use (of those two gameobjects) transform.forward for the ray direction.
I think the should work.
I will try it out, thanks for answer. Any other suggestions?
You can do the rotational math based on the player, but I think provided the blue cube game object is attached to the character (to pick up transform position / rotation) and in turn the ray direction empty gameobjects is the easiest way. The math will be similar to what unity is doing with the transforms anyway.
It's also very visual in the editor (gizmo's and option to attach visual debug shapes to those empty transforms).
Your answer
Follow this Question
Related Questions
How to get an offset of a RaycastHit? 0 Answers
Raycast2D and origin position Offset 1 Answer
Why does this script check for raycast collision? Is it necessary? 1 Answer
Raycast Mouse Position To vector3 1 Answer
Problem With Raycasthit Angle 0 Answers