- Home /
Slowly fade texture only when when looking up?
Hi,
This seems like it shouldn't be too hard but I'm kind of stuck.
I'm not too familiar with Vectors so I'm a little confused. I'm using the angry bot's texture fade script and I'm trying to modify it. I got it to fade when the player looks up, but it also fades when the player spins around at certain rotation angles. How can I make it so it only fades when looking up?
Here's the code:
#pragma strict
var cameraTransform : Transform; var glowColor : Color = Color.grey; private var dot : float = 0.5f;
function Start () { if (!cameraTransform) cameraTransform = Camera.main.transform; }
function Update () { dot = 1.5f * Mathf.Clamp01 (Vector3.Dot (cameraTransform.forward, transform.up) - 0.25f); }
function OnWillRenderObject () {
renderer.sharedMaterial.SetColor ("_TintColor", glowColor * dot);
}
Or this? Sorry for the weird format, I use the code paste but it doesn't work..
#pragma strict
var target : Transform;
var mistColor : Color = Color.grey;
private var angle: float = 0.5f;
var targetDir = target.position - transform.position;
var forward = transform.forward;
function Start () {
if (!target)
target = Camera.main.transform;
}
function Update () {
angle = Vector3.Angle(targetDir, -transform.up) - 0.25f;
if (angle < 90.0)
renderer.sharedMaterial.SetColor ("_TintColor", mistColor * angle);
}
}
Answer by aldonaletto · Feb 02, 2012 at 03:37 AM
The dot product between two unitary vectors result in the cosine of the angle between both. This means that the dot product will return a number between 1 (when the camera is parallel to the other vector) and -1 (when pointing to the opposite direction). In the first script, you could just use Vector3.up as the second vector, like this:
... function Update () { dot = 1.5f * Mathf.Clamp01(Vector3.Dot(cameraTransform.forward, Vector3.up)-0.25f); } ...Using transform.up like in the original code could give strange results if the object was not in the upright position.
Thank you so much, I get it, but it fades when I look down, I want it to fade when I look up. I tried Vector3.down and -Vector.up but neither worked..Any way to fix this?
Edit: Never $$anonymous$$d got it I just used cameraTransform.up ins$$anonymous$$d of cameraTransform.forward.
Thanks again, you've earned this.
Your answer
Follow this Question
Related Questions
Transform a Vector by a Quaternion 1 Answer
Rotate One Object Around Another 1 Answer
slowly rotate a object *need quick fix* 0 Answers
Lookat function moves object backwards 0 Answers
Relative Rotation 1 Answer