- Home /
Problem with Raycast hit
I'm using raycast to move my camera around different positions, it works the first time, but after that it never calls the function again. Also it doesnt work over longer distances even though i know the ray is long enough.
if (Input.GetMouseButtonDown(0))
{
var hit : RaycastHit;
var ray = camera.ViewportPointToRay(Vector3(0.5,0.5,0));
print("mouse down");
if (Physics.Raycast(ray, hit, Length))
{
var hitObject = hit.collider.gameObject;
print("is hitting something");
if (hitObject.gameObject.tag == "Useable")
{
print("hit useable item");
nextCamera = hitObject;
}
}
}
}
It "never calls the function again" - you mean you don't even get it to register the mouse down event after the first time you click?
It is unclear what is going on with your question. As a guess, you should be using Input.Get$$anonymous$$ouseButton(0) ins$$anonymous$$d of Input.Get$$anonymous$$ouseButtonDown(0).
Try this method it helps a lot https://www.youtube.com/watch?v=vhT$$anonymous$$5weADhU
Answer by Stephano · Jun 06, 2014 at 05:18 PM
Problem fixed by removing "Length" from if (Physics.Raycast(ray, hit, Length))
Your answer
Follow this Question
Related Questions
How to engage an object if it's seen by my camera?? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Logic to detect objects entering between the player and camera? 1 Answer
Raycast not rotating with object it casts from 0 Answers
Camera Point-and-click Movement 2 Answers