• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Mar 16, 2014 at 06:03 PM by z3nth10n for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by z3nth10n · Jan 21, 2014 at 05:02 PM · rotationraycastsphere

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image z3nth10n · Jan 21, 2014 at 07:31 PM 0
Share

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

avatar image ArkaneX · Jan 21, 2014 at 11:33 PM 0
Share

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.

avatar image z3nth10n · Jan 22, 2014 at 06:40 AM 0
Share

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Pointing object at mouse using raycast only works when object is center screen. 2 Answers

rotation issue 0 Answers

mouse cursor between two rays 3 Answers

raycast to determine pivot 1 Answer

Rotate object to face up from sphere 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges