Hi everyone,
I’m trying to destroy a cube by using a raycast to hit it every time i press the left mouse button.
While standing perfectly still, this seems to work flawlessly. However, once my character is moving - even if just falling - the GetButtonDown command doesn’t seem to register.
Code Below
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Debug.DrawRay(transform.position, transform.forward * 1000f, Color.green, 1000f);
shooting = true;
}
}
void FixedUpdate()
{
if (shooting)
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit, 1000f))
{
if (hit.transform.tag == "Killable")
{
hit.collider.SendMessage("Hurt", damage, SendMessageOptions.DontRequireReceiver);
GameObject bloodcopy;
Blood.transform.position = hit.point;
bloodcopy = Instantiate(Blood, hit.point, Quaternion.identity);
GameObject.Destroy(bloodcopy, .3f);
}
}
shooting = false;
}
}
At first i thought it had something to do with the raycast itself while i was moving, I turned on drawing of the cast to help see what was happening, but couldn’t see it. I then moved the draw to where it is above, and discovered that it would never draw while moving, but always draw when not moving.
What is going on?