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
0
Question by Voridian · Aug 13, 2013 at 11:59 AM · collisiondecal

bullet decals have wrong rotation C#

sorry for asking another question so soon, this should hopefully be quick. i made a script which makes a bullet leave a decal on the wall where it hits at a 20% chance. this works fine until you try in on walls facing different ways because the decal doesn't rotate to face away from the wall. any quick fix? im currently using the script:

    if(collision.gameObject.tag == "Wall" && Random.value > 0.6) {
                 Instantiate(bulletHole, transform.position, Quaternion.identity);
             }

thanks in advance :)

Comment
Add comment · Show 2
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 vexe · Aug 13, 2013 at 12:02 PM 0
Share

Please surround your code with code tags.

avatar image Voridian · Aug 13, 2013 at 01:45 PM 0
Share

oops i could have sworn that i did, sorry.

2 Replies

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

Answer by vexe · Aug 13, 2013 at 12:07 PM

You are always instantiating your bulletHole with a rotation of Quaternion.identity, you need to have it be facing the wall it collides with, you could do that by getting the normal vector of the wall. Assuming this script is attached to the bullet: looking at it from the surface try

 Instantiate(bulletHole, transform.position, Quaternion.Euler(collision.gameObject.transform.forward));

See if that helps.

Comment
Add comment · Show 6 · 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 Voridian · Aug 13, 2013 at 01:48 PM 0
Share

unfortunately that seems to have no effect, no errors though. thanks anyways

avatar image vexe · Aug 13, 2013 at 01:53 PM 1
Share

Sorry, try collision.gameObject.transform.rotation ins$$anonymous$$d of that Quaternion... - Which means, the rotation of the wall.

avatar image Voridian · Aug 13, 2013 at 02:12 PM 0
Share

still no luck, but i think i know why. this is a very basic fps that i made, the walls are just extruded vertices, the entire map was originally from a single plane in blender, sorry for wasting your time

avatar image vexe · Aug 13, 2013 at 02:15 PM 0
Share

No it's O$$anonymous$$... ^^ this should be very easy to do, let me see...

avatar image vexe · Aug 13, 2013 at 02:34 PM 0
Share

Idk, it sounds right to instantiate it at the walls rotation, could you post all the relative code? what is the bulletHole prefab? a plane with a texture?

Show more comments
avatar image
2

Answer by Linus · Aug 13, 2013 at 01:55 PM

See http://answers.unity3d.com/questions/8494/adding-decals-to-a-object.html

Assuming you are "shooting" using a raycast

 var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
 Instantiate(bulletHole, hit.point, hitRotation);
Comment
Add comment · Show 3 · 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 Voridian · Aug 13, 2013 at 02:08 PM 0
Share

honestly i have no idea what raycasting is

avatar image vexe · Aug 13, 2013 at 02:13 PM 0
Share

A ray is like a line, that you cast from one point to another. It can tell you which/what objects it hits along its way. Best way to handle shooting, I think is raycasting. So when you shoot, you cast a ray, and then check to see what they ray has hit. Did you try collision.gameObject.transform.rotation like I told you? - if you did and it didn't work, then I suggest you learn about Raycasting and how it works, and watch a few tutorials about raycast shooting on youtube. Good luck.

avatar image Voridian · Aug 13, 2013 at 02:24 PM 0
Share

oh, that sounds handy. i did it a totally different way, Instantiate a bullet prefab and AddForce

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

17 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

Related Questions

How to check if an object is colliding with another from another script ? 1 Answer

C# Collision Detection Help 0 Answers

How could it be done "Cooldown" for a shield ? 2 Answers

Having Problem With Performing Collison with two prefab object. 1 Answer

public variable audio clip not initializing sound 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