Forum Thread
  Posts  
Can anyone help me with some Javascript & Unity? (Forums : Coding & Scripting : Can anyone help me with some Javascript & Unity?) Locked
Thread Options
Jake.R.
Jake.R. Writer
Jun 2 2014 Anchor

So I have a spotlight but I need it to stay in one place - on the ground.Whilst the beam (the end) needs to follow and point at the mouse. I have absolutely no idea how to do this. So the beam kind of needs to rotate around an anchor at it's source.

All I can find is how to make the light follow the mouse at its source. Rather than just the beam facing the mouse.

Thanks guys

--

We can forgive a man for making a useful thing as long as he does not admire it.  The only excuse for making a useless thing is that one admires it intensely.

All art is quite useless.

Nov 2 2014 Anchor

You need to do a raycast from the screen, passing through the position of the mouse, this will get the position in the game that the mouse is hovering over
save this in a Vector3 then do
transform.LookAt(mouse_Pos_Vector);
The code above needs to be in the light sources script.
I haven't actually tried this, but I assume it works.

Feb 1 2015 Anchor

Do a Raycast from player(Main camera) to the center of screen (where the player is looking at) and store that Vector as a Variable and use it on the torch as "Look at variable(Name of variable you stored the Vector of the ray).

If you're not familiar with Raycast look into the documentation.

Mar 29 2015 Anchor

It would also be wise to call it within an Update() function but you probably already knew that.

--

A pancake walrus!

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.