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 Marsallima · Feb 07, 2012 at 02:29 PM · raycastcolliderfpsdistancehit

Hit distance Change light range

Hi guys, i am trying to define the light range to the Hit.distance ( the light is a flash light to a weapon ) but the light is defective :/ have other way?

The Script :

 function Update () {
 
 var Hit : RaycastHit;
 
 var Range : float = Mathf.Infinity;
 
 var DirectionRay = transform.TransformDirection(Vector3.forward);

 Debug.DrawRay(transform.position, DirectionRay * Range, Color.white);
 
 if(Physics.Raycast(transform.position, DirectionRay, Hit, Range)){
 
     light.range = Hit.distance;
     light.intensity = Hit.distance;
 
 }

}

Comment
Add comment · Show 4
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 duck ♦♦ · Feb 07, 2012 at 04:44 PM 0
Share

what do you mean when you say the light is defective? does the light illu$$anonymous$$ate anything at all? even a test object which is well within the range?

avatar image Marsallima · Feb 08, 2012 at 01:14 AM 0
Share

The light not "touch" the gameObject correctly ( the cookie by half )

avatar image Berenger · Feb 08, 2012 at 01:22 AM 0
Share

When you look the Gizmos of the light range, does it touch the hit point ? even if it does, the light attenuation will make it difficult to light it. Have you tried a projector and change the far plan ins$$anonymous$$d ?

avatar image Marsallima · Feb 08, 2012 at 04:11 AM 0
Share

How i make this? xD But, how the best way?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Marsallima · Feb 08, 2012 at 04:40 AM

Problem Solved:

var additionalPosition : float;

function Update () {

var Hit : RaycastHit;

var Range : float = Mathf.Infinity;

var DirectionRay = transform.TransformDirection(Vector3.forward);

Debug.DrawRay(transform.position, DirectionRay * Range, Color.white);

 if(Physics.Raycast(transform.position, DirectionRay, Hit, Range)){
     
     var distance  = Hit.distance * additionalPosition;
     
        light.range = distance;
 }

}

( I do with the lighting grip the object Normal Distance + something ^^ ) What do you think?

Comment
Add comment · Show 5 · 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 Berenger · Feb 08, 2012 at 04:45 AM 0
Share

Well if it works, can't be bad ^^ But nevertheless, give a shot to the projectors, might be usefull an other time. Asset->Import package->Projectors. There is a shadow, spot light and grid, it's pretty cool. And the cost is ridiculus compared to a ligth.

avatar image Marsallima · Feb 08, 2012 at 05:03 AM 0
Share

But, how i use projectors? you have some tutorial about projectors (that can apply to my question) ^^

avatar image Marsallima · Feb 08, 2012 at 05:10 AM 0
Share

1 more question... xD How i make to the var distance change smooth?

avatar image Berenger · Feb 08, 2012 at 05:28 AM 0
Share

Once you've imported the asse, just drag the prefabs into the scene. Basically, it project a picture ahead. So when that picture is a white circular gradient (like particle default material tex) it looks like a spot light.

For the smooth distance, there some coding. A coroutine would work great here (I'll stay in pseudo-code, with documentation you should be ok ;))

if( raycast )

 Expand$$anonymous$$yLight( hit distance );

function Expand$$anonymous$$yLight ( distance )(

 timer = 0

 while( timer > duration)(

     light.range = interpolate( range$$anonymous$$in, distance, timer / duration )

     timer += deltaTime

     wait next frame // That one isn't obvious, it's yield null
 )

)

Sorry for the poor code formatting, I have no idea how it works in comment ...

avatar image Marsallima · Feb 09, 2012 at 06:56 AM 0
Share

Thanks, but the projector give me the same "error" of the light ( with Cookie ) :/ The image is not "fixed" properly to the wall... And so it is I need to increase the distance But this causes the biggest problem, if something is behind, will also stay with the light.

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

6 People are following this question.

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

Related Questions

how to get info on what raycast hitted 1 Answer

Linecast from raycast hit point 1 Answer

what is the best way to detect if an object has been clicked on? 1 Answer

RaycastHit.distance 1 Answer

Raycast hit working in unity editor but not in deployed webplayer build? 0 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