Hello,
I’m using raycasts to shoot a rocket. However, it goes straight through colliders sometimes. I checked some of the basics and made sure my code was in FixedUpdate and made sure my distance wasn’t too small. Also, tried debugging rays and they go straight through the collider and still no collision.
Here is my code:
void FixedUpdate () {
movement = (forward.normalized * force) - downMovement + boost;
nextPosition = raycastSpot.position + movement;
distance = Vector3.Distance (raycastSpot.position, nextPosition);
distance += 10f;
rotation = Quaternion.LookRotation (movement.normalized, Vector3.up);
Debug.DrawRay (raycastSpot.position, movement, Color.white);
RaycastHit hit;
if(Physics.Raycast(raycastSpot.position, rotation.eulerAngles, out hit, distance)){
//This is not called VV
hitSomething (hit.point, hit.normal);
}else{
transform.position = nextPosition - (movement.normalized * offset);
transform.rotation = rotation;
}
Debug.DrawRay (raycastSpot.position, movement, Color.blue);
if (boost.y > 0f) {
boost -= boostSubtract;
} else {
boost = Vector3.zero;
}
}
“boost” is just a vector3 adding some upward force at first that is taken away over a few frames by “boostSubtract”
The blue ray is just to give me and idea where the rocket will be next frame, even though it is slightly off.
The white ray tells me exactly where is was at the start and end of the frame.
Pictures:
It does work sometimes, I have two more pictures showing it colliding into the terrain, but I cant upload any more pictures on this post.