- Home /
How Can I Adjust My Ray Cast Position Upwards?
Hello,
How would I go about making this line of code move my ray cast +10 up (y):
var direction = transform.TransformDirection(Vector3.forward); var hit : RaycastHit; var localOffset = transform.position + transform.up * 10;
// Did we hit anything?
//transform.position + transform.up * 10
if (Physics.Raycast (localOffset, direction, hit, range) && MachineGun == true) {
Debug.DrawLine (transform.position, hit.point);
// Apply a force to the rigidbody we hit
if (hit.rigidbody)
hit.rigidbody.AddForceAtPosition(force * direction, hit.point);
so in the transform.position (I would imagine), I want something like:
transform.position + 10 on Y axis
So it would move my ray cast up slightly, right?
Cheers
Answer by Statement · Dec 17, 2010 at 01:06 AM
How would I go about making this line of code move my ray cast +10 up (y):
Just add 10 up?
// 10 world units up: var worldOffset = transform.position + Vector3.up * 10; if (Physics.Raycast (worldOffset, direction, hit, range)
// 10 local units up: var localOffset = transform.position + transform.up * 10; if (Physics.Raycast (localOffset, direction, hit, range)
Nearly - thats appears to be rotating my ray cast upwards towards the end of the ray. The start of my ray cast is still annoyingly low
Updated my answer. It's probably just a case you want the offset in local space and not in world space. See my second line of code.
Its still going upwards diagonally. The start of the cast is still at 0
All I am using is the standard FPS tutorial from Unity and just adjusting the position of the ray via script. Humm, interesting
Your answer