Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by Karsnen_2 · Nov 22, 2012 at 09:17 PM · cameraiosraycastcollider

Logic to detect objects entering between the player and camera?

Hello,

I have a Camera following a player and at times, Object enter between the player and the camera. Now more 75% of the time, the camera and the player are separated exactly by 40 units.

Target : iPad

Game View : X-Z i.e. the player falls down due to gravity and camera follows the player.

Now the objects which enter have collider and some do not. To make things simple I am only considering the one with a collider. They do not have rigidbody.

Function Setup : I have script upon the parent of the gameobject that enter the space between the player and the camera. That script has two public functions which are responsible for transparency ON and OFF. Now these functions can just be called once to perform it's respective tasks.

Problem:

  • I have to call them when it enter the space and also exits the space between the camera and the player.

  • As these object are plenty in number & my target is iPad I can't use rigid bodies.

POSSIBLE SOLUTIONS: - Planned to use colliders but the thing is I have to use Rigid Bodies in order to use them. - Raycasting/Spherecasting etc could be used, but how do I revert the transparency when the GObject exist the intermidiate space.

Thanks Devs

regards,

Karsnen.

Comment
Add comment · Show 5
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 whydoidoit · Nov 22, 2012 at 09:37 PM 0
Share

So were you thinking that you want the transparency ON when the object is anywhere between the player and the camera or only if it would occlude some part/all of the player's avatar?

avatar image whydoidoit · Nov 22, 2012 at 09:38 PM 0
Share

BTW if it's moving it and it has a collider you should attach a kinematic rigidbody even if you don't want physics. The cost is high otherwise.

avatar image Karsnen_2 · Nov 22, 2012 at 09:42 PM 0
Share

Whydoidoit :

First part of your question : I want the transperancy ON when the object is "anywhere" near the player & camera. The purpose is to give the user more view of the environment. I hope you get what I mean here. The basic notion is that, I do not what those gObjects to obstruct the view and clog the screen space.

Second part of your question : I am not sure what you meant when you said occlude part/all of the player's avatar.

avatar image whydoidoit · Nov 22, 2012 at 09:45 PM 0
Share

I mean - 1) if the distance between the camera and the object is less than the distance between the player and the camera it should be transparent?

Versus - 2) it should be transparent if the player cannot be seen because it is in the way?

1 is mathematics, 2 is raycasting...

avatar image Karsnen_2 · Nov 23, 2012 at 01:59 PM 0
Share

$$anonymous$$Ike, Thanks for your reply. I was thinking about $$anonymous$$athematics only. But I am going to have a lot of such objects in the environment and there are going to be a lot of update functions. So considering my target as iPad, is that expensive?

Similarly on the other hand, if I happen to use Raycasting - how do I revert the transparency when it has to be visible as soon as it exits the raycasting? Could you pl

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · Nov 22, 2012 at 09:52 PM

So you could call your transparent ON/OFF methods based on this for closer to the camera

Player.cs

  public static float distanceSquared;
 void Update()
 {
      //note you should cache transform and Camera.main.transform for performance
      distanceSquared = (transform.position - Camera.main.transform.position).sqrMagnitude;
 }
 

Thing.cs

   void Update()
   {
    if((transform.position - Camera.main.transform.position).sqrMagnitude < Player.distanceSquared)
    {
         //Make it transparent: e.g.
         renderer.enabled = false;
         //or
         var c = renderer.material.color;
         c.a = 0.3f;
         renderer.material.color = c; //presuming that material is transparent in some way
    }
    else 
    {
         //Make it opaque: e.g.
         renderer.enabled = true;
         //or
         var c = renderer.material.color;
         c.a = 1f;
         renderer.material.color = c; //presuming that material is transparent in some way
    }
   }
Comment
Add comment · Show 1 · 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 Karsnen_2 · Nov 23, 2012 at 02:01 PM 0
Share

Regarding changing the transparency, I do not have a transparent shader upon it. Hence first I switch the shader to a transparent one and then lower the alpha value. Then when I want to revert it back to the original one, I revert it back to $$anonymous$$obile/Bumped Diffuse. Is that okay?

Thank you $$anonymous$$ike. I am going try the above code.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

RaycastAll related question 1 Answer

Physics.Raycast not checking layermask properly? 1 Answer

Can't get a laser working properly. 2 Answers

Dragging an object in iOS (UnityScript) 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges