Jump to content

How do I attach a light to a mesh ?


altreality
 Share

Recommended Posts

Yep, and remember the light.setDirectionToTarget(anyMesh.position)... for spotlights and directional lights.  It's handy, for testing, initial setting, and in animation loops.  See http://www.html5gamedevs.com/topic/11288-strange-shadows/#entry65523 posted moments ago.  :)

 

orientation = direction, in case anyone is curious (Gryff was speaking correctly).  Generally, one does not rotate spot lights and directional lights.  Instead, one sets their .direction.  (At least that's how I understand it.)

 

Have I plugged my function enough, yet?  :) light.setDirectionToTarget() is the only code that I have ever contributed to BJS.  I'm so proud.  hehe  Almost 4 lines of code!

Link to comment
Share on other sites

Ah yes right, forgot totally about the orientation. So I need to get the direction of my car and then point the spotlight in that direction.

So say I want to align the spotlight to always point towards the x axis of a box mesh(lets say the x-axis is the forward direction), then how do I get its current transform in space and use that to set the light direction ?

Strangely, the direction of the light is in fact changing here: http://playground.babylonjs.com/#2AKHZK#5

Link to comment
Share on other sites

altreality: Glad you have things figured out :)

 

Here is a demo I made a few months back - originally it used a point light  - but I've changed it to use a spotlight. Both the camera and the spotlight are parented to an animated cube that follows a path. Consider this a racing car  :o

 

Animated Light

 

Nadolig Llawen,

 

gryff :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...