• 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 Travis 2 · Dec 02, 2010 at 12:25 AM · raycastingdecal

Need some explinations for raycasts and decals

I know this is something i should know but i looked everywhere on google and i need someone to simply explain what a decal is refering to and what its used for, and also how do i use raycast for say like a bullet.

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

3 Replies

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

Answer by AVividLight · Dec 02, 2010 at 12:28 AM

Hey Travis,

I can explain raycasting, but I don't know what a decal is either... raycasting is basically a lazer, and when something (Or someone) crosses it, it can trigger something to happen. If you want a actual example, please just let me know.

-Edit-

Here is a script I have that checks the distance between the ground and "you"...

//Written by/for Gibson Bethke

var Counter : float = 0.0; var maxCounter : int = 0; var terrain : Terrain; var Player : Transform; var Guitext : Transform;

function Update () {

     var up = Player.TransformDirection (Vector3.up);
     var hit : RaycastHit;
     Debug.DrawRay(transform.position, -up * 5000, Color.green);

     if(Physics.Raycast(Player.position, -up, hit, Mathf.Infinity)){
         Counter = Vector3.Distance(Player.position, hit.point);

         if (Counter > maxCounter) maxCounter = Counter;

         if(Counter <= 10){
             Guitext.guiText.text = "You're at ground level    Top Height: " +maxCounter;

         }else{
             Guitext.guiText.text = Counter+ " Meters";

             if(Counter >= 10){
                 Guitext.guiText.text = Counter+ " Meters       Top Height:   " +maxCounter+ " m";
             }
         }
     }
 }

-Hope I Helped, Gibson

P.s. Sorry, I'm not very good at adding comments into scripts, so I'll explain it...

These are all the variables, You don't need this many, I just like variables, and being able to change things without going into the script.

var Counter : float = 0.0;
var maxCounter : int = 0;
var terrain : Terrain;
var Player : Transform;
var Guitext : Transform;

This means Run Every Frame, so by saying this, I am telling the script to run every frame that the game is running (I know you know some of these things, but incase someone else reads this, it might be helpful)

function Update () {

Now, I'm declaring a variable in this function, so only the script uses it... The variable is "up", which I defined as the direction...

var up = Player.TransformDirection (Vector3.up);

This line is simple... It defines "hit" as when something crosses the "lazer"...

var hit : RaycastHit;

This line is not necessary... All it does is tell Unity to display a line in the scene view... The "* 5000" is just telling it how long the line should be... (You can see were using the "up" variable we set up earlier)

Debug.DrawRay(transform.position, -up * 5000, Color.green);

Now were getting into the more serious stuff... The first thing that this line does is check if the conditions are met... Then, if its true, it fires the "lazer" (Ray) negative "up", or down... Then it tells the distance to Counter (The variable).

 if(Physics.Raycast(Player.position, -up, hit, Mathf.Infinity)){
 Counter = Vector3.Distance(Player.position, hit.point);

For some reason, I find this line funny... Thats probably not a good thing... Anyway, this line checks if Counter (A Variable) is bigger than maxCounter (Another variable)... If it is, maxCounter becomes Counter (Thus setting the high score)...

if (Counter > maxCounter) maxCounter = Counter;

The next line is similar to the previous line... It checks if counter is smaller than 10 (Other than checking if its greater than maxCounter)... If Counter is smaller than 10, Guitext (A variable) is told to say, "You're at ground level" Then display the Top Height (A variable, like a high score)

if(Counter <= 10){
            Guitext.guiText.text = "You're at ground level    Top Height: " +maxCounter;

Here's something we haven't covered yet... "}else{"... It means that if the requirements are not met (if statements are false), "this" happens... And all the this line does is display Counter (The variable) and say meters, as long as your not at "Ground Level"...

}else{
            Guitext.guiText.text = Counter+ " Meters";

And finely, the last line... This one tells you what height your at, as long as your above 10...

if(Counter >= 10){
                Guitext.guiText.text = Counter+ " Meters       Top Height:   " +maxCounter+ " m";

If you have any other questions, please feel free to ask!

-Hope I helped, Gibson

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 The Game Object · Dec 05, 2010 at 10:50 AM

decals are basically temporary textyres triggerd by an event such as bullets hitting a surface wich would create bullet holes, the bullet hole textyre is applied to therever the bullet hit, there are a few ways to do it, but they look the same. it just affects the performance if u pick the most graphic intensive or script intensive it will be un balanced try to balance them to hace better effect. hope this helped

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 Travis 2 · Dec 02, 2010 at 12:43 AM

Thanks That is alot of help im just trying to learn a bit more about programming before i start college for it. That comfirmed my theory about raycasting an example would be great. like say a raycast coming out of a gun to save on poly's or maybe like a trigger to run an application to load a level. thx :)

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

No one has followed this question yet.

Related Questions

Adding bullet holes to walls 3 Answers

projectors vs. textures on plane with alpha channels 1 Answer

Bullet hole attach to movable object? 1 Answer

How do I wrap blood decals around meshes that are not just a flat plane? (e.g. blood spatter on a round lamp) 0 Answers

Realtime Skin Mesh Decals 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