var lighttype : GameObject;
var empty : GameObject;
function Update () {
LightRay();
if (LightRay.hit.point == ground.solids){
lighttype.transform.position = (LightRay.hit.point);
empty.transform.position = (LightRay.hit.point);
}
}
function LightRay() {
var hit : RaycastHit;
var ray : Ray = camera.ScreenPointToRay (Input.mousePosition);
Debug.DrawRay (ray.origin, ray.direction * 100, Color.yellow);
if (Physics.Raycast (ray,hit ,1000)) {
var distanceToGround = hit.distance;
print (distanceToGround);
print ("Hit something");
lighttype.transform.position = (hit.point);
}
}
function ground(){
var solids : GameObject[];
solids = GameObject.FindGameObjectsWithTag("Solid");
}
I’m trying to cast a point light that follows my mouse and shines on the area of the scene the mouse is at. Only problem is it only lights up whenever it passes over a gameObject and shines light on gameobjects when it is near. It doesnt shine any light on the terrain. I would use a spot light but im not sure how to make sure it has the same angles as the ray thats being cast.
Nah, its just with certain settings and lightmaps , different results can be achieved, sometimes not intentionally. But if you have no lightmaps baked in at all , thats not going to be an issue at all in this case… hmm.
Edited :
now I will read the script , I just threw that out there on a whim before i even read rest of thread , haha.
Ok so your running this in your play mode? i dont see how (at least , not without errors.) and im guessing you have a Light assigned to the lighttype gameObject, what about the empty gameObject… What is assigned to that variable?
I just through your script in ed, hit play , and wham null ref error
LightRay.hit.point == ground.solids
Script looks pretty whonky to me, im honestly not to sure how you have that running. Lol, add #pragma strict to that and be prepare to be amazed…
i have a point light assigned to light type. and ive tried using and not using an empty gameObject in the empty gameobject. I only tried the empty thinking that if i assigned a collider to it the light would always point at it and shine through it like im kind of looking for.
Were you following a tutorial from somewhere ? If so , please do direct me to it …
At any rate , that entire approach that your using in code (again , maybe im out of my f*&kin mind at the moment from lack of sleep, and somehow have been missing a very key approach to ,.,) is just not right.
By the way, back to the original topic at hand …why not just have a point light move based on the mousePosition, and clamp its y value or use an alternate method to control its height.
EDITED : seriously this time, gotta get sleep , i will check in wit ye in the morning if not resolved
you are doing 4 raycasts there as you call the function 4 times. you should call it 1 time and store its return value which you need to return in LightRay().
also you should add a certain height to your light as it can be an issue when it is directly on your terrain (where the ray hits). i’m not sure if that is the problem. and maybe there are special settings required for using lights on the terrain? i darkly remember to have read somewhere that terrain can only use directional light.
maybe an projector is what you should look for. with that you can put a bright alpha texture beyond your light and simulate light (similar to shadow).
I think you may be right on the directional light being the only usable thing. I edited out the redundancy in my code. I will look into setting up a projector.
as i told i’m not sure if this works this was just an idea. but as you can do objectshadows with projectors (with a dark texture) it would be logical if you could do light with this also (with a bright texture). so create a transparent texture and draw a white/yellow filled circle on it with a certain transparency (try 0.5 fe). project this at the position and you should see it brighter than before.
you could also look in the material settings and try a glow shader or something like that. you need a transparent shader anyway.
The very next morning … and now i shall explain the pragma strict. The reason it is throwing all those errors, is because it is telling you that the variables you are trying to access within those methods are not accessible. In all my time programming, i have never seen that (and once again, maybe im nuts and just missed a great beginners claass one day), but , as i said never seen that before.
(im no pro so …)
To the best of my knowledge, in any language i have ever used, if you wish to pass, handle , retrieve data from within another method , you either need to have the variables global, or , used as parameters which are in turn handed to the method, and returned at a methods end.
Again , someone please correct me if im wrong. As far as i know - that code wont ever work like that.
#pragma strict
var lighttype : GameObject;
function Update () {
LightRay();
}
function LightRay() {
var hit : RaycastHit;
var ray : Ray = camera.ScreenPointToRay (Input.mousePosition);
Debug.DrawRay (ray.origin, ray.direction * 100, Color.yellow);
if (Physics.Raycast (ray,hit ,1000)) {
var distanceToGround = hit.distance;
print (distanceToGround);
print ("Hit something");
lighttype.transform.position = (hit.point);
}
}
this is my new script updated to get rid of the errors. I still have the same issue. I tried doing the projector as exiguous said but i couldnt get that to work either.
thats better, but im still kinda unclear really why you even need to use this method to handle the light, Try just adding a script to the light which reads the mousePos and moves the light respectivly. As for the height of the light , use a custom method to keep it @ a steady value. Again though , maybe you have a very valid reason im unaware of.
Not at all, however, lightmaps, and pixel light count can be a reason why some lights wont show,