Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Alkan · Oct 12, 2011 at 03:35 PM · projectorblob shadow

Best practice for making blob shadow projector always face down?

I've come across 2 methods so far, one which involves making the projector a child of the object casting the shadow and then using this script on the projector itself:

 function Update () {
     var facedown = Quaternion.identity;
     facedown.eulerAngles = new Vector3( 90, 0, 0);
     transform.rotation = facedown;
     }

Which sort of works... but seems to have weird artifacts when the parent object rotates - and the second method which involves copying the objects position information over to the projector's position information:

 var objectToFollow : Transform;
 var offset : Vector3;
 
 function Update () {
     transform.position = objectToFollow.position + offset;
 }

I haven't tried the second method yet, but I figure the projector can no longer be a child of the main object which sounds like it could become quite messy.

Any tips?

Comment
Add comment · Show 12
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Michael 12 · Mar 19, 2012 at 09:50 PM 0
Share

That 2nd method ROC$$anonymous$$S!! I just place the projector into an epty game object placed at ground level with the projector above facing downwards, applied the script, assigned my character, SWEEETNESS it's simplicty at it's best!!

avatar image ActionScripter · May 24, 2012 at 04:10 PM 0
Share

I want to offer this handy script for the second method, which improves it by automatically making the shadows imitate the sun angle. Just slap it on the projector and assign the variables in the inspector, and you're all set!


// ShadowFollow.js

#pragma strict

var objectToFollow : Transform; // The object you need a shadow under

var offset : Vector3; // How much to shift the projector from the object center

var lightSource : Light; // What light is "casting" the shadow

function Start () {

 transform.rotation = lightSource.transform.rotation;

}

function Update () {

 transform.position = objectToFollow.position + offset;

}

avatar image Michael 12 · May 25, 2012 at 05:23 PM 0
Share

Very handy script, I did notice however that it casts the shadow in the wrong direction so it does not match up with my light mapped shadows, any way to fix that to make it more accurate? Also trying to figure out how to make it so as when my enemy character is destroyed that the blob shadow projector also gets destroyed because right now I get an error message: $$anonymous$$issingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

avatar image ActionScripter · May 25, 2012 at 05:44 PM 0
Share

Hmm. Well, it's designed for use with a directional light, such as the sun, which means the angle of the shadow never changes. However, you CAN modify it to work with scene lights. Here's how I'd do it.

Ins$$anonymous$$d of setting the rotation in the Start() function, you'll need to set it in Update(). In addition, the rotation will not be set to the light's rotation. Ins$$anonymous$$d, you will need to calculate a vector for transform.position - lightSource.transform.position, then find the rotation of that vector, then use THAT rotation for transform.rotation.

So in the end, the rotation part would look something like:

 function Update () {
 
     var shadowVector : Vector3 = transform.position - lightSource.transform.position;
 
     transform.rotation = Quaternion.lookRotation(shadowVector);
 
     (... other stuff already in Update)
     
 }
avatar image ActionScripter · May 25, 2012 at 05:48 PM 0
Share

Oh, and as for your second question... I would try making the shadow part of a Prefab, including both the character and the shadow projector. When the enemy needs to die, kill the whole Prefab.

There are other ways to do this, too. For instance, you could have the Update() function include a check to see if the object is still in existence:

 if (!transform)
     <delete whatever>
Show more comments

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Meltdown · Oct 12, 2011 at 04:51 PM

Instantiate the shadow casting object, then instantiate the projector seperately. It has no reason to be a child of of the object, as the rotation will cause problems.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Meltdown · Oct 12, 2011 at 04:04 PM

The second method is the way to go. Nothing messy about it :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Alkan · Oct 12, 2011 at 04:48 PM

If I'm instantiating the shadow casting object, where would you recommend I place the projector?

Do I instantiate it along with the object at the same time - or is there a way I can nest it in with the object-prefab as a child?

,I see, if I'm instantiating the shadow casting objects, would you advise that I also instantiate the shadow projector at the same time?

or could I make a prefab that contained both?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Meltdown · Oct 12, 2011 at 04:49 PM 0
Share

You should post this as a comment to my answer... not as an 'answer'

avatar image Alkan · Oct 13, 2011 at 10:38 AM 0
Share

point taken!

avatar image
0

Answer by austint30 · Jan 05, 2014 at 06:09 AM

I used this script for my car shadow, but the shadow does not rotate with my car!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

blob projector ignores floor without ignore layer?!? 0 Answers

Blob shadow projector is not projecting properly 2 Answers

UnityEngine.Input.GetMouseButton(1)) issue 1 Answer

Projector - blob shadow. How to change the material's alpha channel C# 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges