- Home /
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 :).
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.
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;
}
}
}
$$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);
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;
}
}
If i remember correctly, in Amnesia, sanity reduction is triggered when you are in the dark, you see monster or monster sees you.
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
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
Your answer
Follow this Question
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