- Home /
The question is answered, right answer was accepted
Infinite Raycast?
Hi,
well I know that it is impossible (because the skybox is only a texture, no a solid thing), but I use a sphere that follows the player (so the player is inside it) and the problem is that inside it nothing is detected...
Ray ray = Camera.main.ScreenPointToRay (new Vector3(Screen.width/2,Screen.height/2,0));
RaycastHit hit;
if (Physics.Raycast (ray, out hit)) {
holdedItem.transform.LookAt(hit.point);
holdedItem.transform.rotation *= Quaternion.Euler(Slots.HotBarSlots[selectedSlot].FcustomRotation);
}
That code is for rotate the current object (in the Inventory, but this is not relevant, the only things important is say that the current object is near the camera, so it can be showed by the camera behind him) to the area where the player is looking (exactly on the center of the screen)
But when I look to the sky the rotation return zero (it's normal because the sky isn't solid), but as I said before I use a sphere, that is not detected... I don't know why... D:
So, how can I make the sphere solid in its inside part for make a "Infinite" Raycast system?
Thanks in advance. Bye.
Answer by ArkaneX · Jan 21, 2014 at 05:51 PM
Your sphere is not detected, because Raycast can't detect colliders from the inside. There is a short info about this in the official docs.
Well thanks, but I need solutions... Is there another way to do this? $$anonymous$$aybe not with a Raycast, but a code that does the following thing: Rotate the current object (because when I look down the weapon that I have on the scene it's frontal face is looking fowards, and I want that face looks to the ground), by following the mouse, or a point of the screen.. I don't what can do that, so... Can you help me with this? Thanks. =3
If I understand you correctly, and the raycasting is required only to find the point where your character is looking, then you can find this point using:
var point = Camera.main.transform.position + Camera.main.transform.forward * 100f;
I used 100f as an example only, but it should be ok if the rotating object is near the camera. With this solution you don't need any sphere surrounding the player.
I see some shooters, and I think that the weapon is inside the camera, so when the player look to another part the weapon moves and rotates with the camera, I have some shooters, I will check that later, and I will say you. :P