• 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
0
Question by SonicDirewolf · Jan 20, 2018 at 01:15 PM · 2draycastshadowblob shadow

Blob Shadow effect using raycast on a jumping object (2D)

I have a player that jumps on platforms. I need a simple blob (circle) shadow under the player. I could've made a child object with a pre-made image of a shadow and attached it to the player, but the player can jump, so this won't work. Can I achieve this using Raycast? Enable the shadow object only when the raycast hits a 2DCollider and enable it at the end position where the raycast hit? If yes, then how can I do that? Thank You!

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · Jan 21, 2018 at 05:53 AM

 raycasthit _info;
 ray _ray;
 _ray.direction = //direction;
 _ray.origin = player.transform.position;
 
 physics.raycast(ray, out _info);
 
 gameobject Shadow;
 
 Shadow.transform.postion = _info.point;
 Shadow.transform.lookat(- _info.normal);

that look at will make it look right at the wall or whatever it just hit.

pseudo code so possibly minor mistakes.

Comment
Add comment · Show 1 · 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 SonicDirewolf · Jan 21, 2018 at 03:07 PM 0
Share

Doesn't work! Giving a lot of errors. Used this ins$$anonymous$$d but it's still not working!

 public class Raycasting : $$anonymous$$onoBehaviour
 {
 
     public GameObject shadow;
     public GameObject player;
 
     private void Update()
     { 
 
         RaycastHit hit;
 
         Physics.Raycast(transform.position, -Vector3.down, out hit);
 
 
         shadow.transform.position = hit.point;
         shadow.transform.LookAt(hit.normal);
     }
 
 
 }
avatar image
0

Answer by Tortuap · Sep 17, 2020 at 02:05 PM

Based on SonicDirewolf version I wrote this, that works well in 3D :

 public class RaycastedShadowImposter : MonoBehaviour
 {
     public float raycastLength = 10;
     public float upDecalFromFloor = 0.05f;
 
     private void Update ()
     {
         Ray ray = new Ray ( transform.position + ( Vector3.up * raycastLength ), Vector3.down * raycastLength );
         if ( Physics.Raycast ( ray, out var hit ) )
         {
             transform.position = hit.point + ( Vector3.up * upDecalFromFloor );
             transform.LookAt ( transform.position + hit.normal );
             
             Debug.DrawLine ( hit.point, hit.point + ( hit.normal * 5 ) );
         }
     }
 }

To put on a GameObject that contains a SpriteRenderer.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

173 People are following this question.

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

Related Questions

Layer Mask on raycast2d not working? 1 Answer

Finding any objects below or above object at ANY POINT? 1 Answer

Getting a Raycast rope to follow its object 0 Answers

2D Character Controller Movement Issues 0 Answers

onGround raycasts return onGround is true while colliding with platform sides 0 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