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 TheHoongs · Dec 31, 2013 at 10:01 AM · raycasttriggersee

Sanity system like amnesia

Hey guys,I am starting to get in the world of unity.

I am making a horror game,but I need a sanity system that when you look at a gameobject for too long,the screen will fade to white and brings you to another scene.I made a script but it does not work.

Hopefully you guys can help me :).

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by YoungDeveloper · Dec 31, 2013 at 10:03 AM

Then show us your script, tell what exactly didn't work and how you tried to solve your problem. Otherwise sounds more like you want a freebee script, instead of understanding the problem.

Comment
Add comment · 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
1

Answer by MagicoCreator · Dec 31, 2013 at 12:20 PM

you need something like this:

 var ray : Ray = camera.ScreenPointToRay (Vector3(Screen.width/2f,Screen.height/2f,0));
 var raylength : float = 10;
 var hitinfo : RaycastHit;
 var Sanity : float = SANITY_MAX;
 
 function Update(){
    if(Sanity < 0){
       //your magic here 
    }
    if(Physics.Raycast(ray,hitinfo,raylenth)){
       if(hitinfo.transform.tag == "don't look at this"){
          Sanity -= Time.deltaTime;
       }
       else if(Sanity < SANITY_MAX){
          Sanity += Time.deltaTime;
       }
    }
 }
Comment
Add comment · Show 7 · 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 Bunny83 · Dec 31, 2013 at 12:44 PM 0
Share

$$anonymous$$eep in $$anonymous$$d that you have a ray length of 10 so the raycast might hit nothing. In this case you don't increase the Sanity variable.

An easy fix is something like that:

 //[...]
 if(Sanity <= 0){
 
 }
 
 var direction = 1.0;
 if(Physics.Raycast(ray,hitinfo,raylenth)){
     if(hitinfo.transform.tag == "don't look at this"){
         direction = -1.0;
     }
 }
 Sanity += direction * Time.deltaTime;
 Sanity = $$anonymous$$athf.Clamp(Sanity, 0, SANITY_$$anonymous$$AX);
avatar image MagicoCreator · Dec 31, 2013 at 12:53 PM 0
Share

yeah i messed it up, what i intented to write was this:

 var ray : Ray = camera.ScreenPointToRay (Vector3(Screen.width/2f,Screen.height/2f,0));
 var raylength : float = 10;
 var hitinfo : RaycastHit;
 var Sanity : float = SANITY_$$anonymous$$AX;
  
 function Update(){
    if(Sanity < 0){
       //your magic here 
    }
    if(Physics.Raycast(ray,hitinfo,raylenth)){
       if(hitinfo.transform.tag == "don't look at this"){
          Sanity -= Time.deltaTime;
       }
    }
    else if(Sanity < SANITY_$$anonymous$$AX){
       Sanity += Time.deltaTime;
    }
 }
avatar image YoungDeveloper · Dec 31, 2013 at 12:55 PM 0
Share

If i remember correctly, in Amnesia, sanity reduction is triggered when you are in the dark, you see monster or monster sees you.

avatar image MagicoCreator · Dec 31, 2013 at 12:58 PM 0
Share

i never played amnesia, but the asker wrote "if you look at a gameobject too long" so thats what i did (assu$$anonymous$$g its FPS since i know amnesia is), and added regeneration

avatar image YoungDeveloper · Dec 31, 2013 at 02:16 PM 0
Share

I didn't mean it like pointing in the face that your code is wrong. $$anonymous$$ore like an information for question asker itself. So for the complete Amnesia style sanity, he will need:

  • Ray check for player, can you actually see the monster

  • Ray check, Eye field of view for monster, this is not a single ray cast

  • Zones which represent darkness, which trigger sanity reduce

Show more comments

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

21 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 avatar image avatar image

Related Questions

Trying to play other objects' sound and animations from Raycast hit 1 Answer

Want Object A to send a message to Object B when it is directly above it 3 Answers

Use OnTriggerEnter during a transform ! 0 Answers

Can I make SphereCast work with triggers? 2 Answers

Make raycast ignore some triggers but hit some others? 2 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