Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 talyon · Jun 07, 2014 at 03:31 PM · c#vector3bulletbouncing

Bullet bounces off the wall

Hello to everyone

I wanted to make a script that makes the bullet bounced three times on the wall, this is what I tried to do.

 private  Vector3 velocity; 
 
 public float speed;
 
 private int n = 0;
     
     
     void Awake()
     {  
         velocity = this.transform.forward;
         speed = 10;
     }
     
     
     void Update()
     {
         this.transform.position += velocity * Time.deltaTime * speed;
     }
     
     
     void OnCollisionEnter( Collision info) 
     {
         if ((info.gameObject.tag == "Muri") && (n<3))
         {
             n++;
             foreach(var contact in info.contacts )
             {
                 velocity = Quaternion.AngleAxis(180, contact.normal) * transform.forward * -1;
             }
         }
         else 
             Destroy (gameObject);
 
     }

It works pretty but there are three problems:

1)Occasionally through the wall.

2)Occasionally does as in the pictures.alt text 3)Occasionally increases the speed.

It is very likely that I'm completely wrong way, then you do another picture for you to understand what should happen. alt text

I hope I was clear, and I apologize in advance if it's a stupid question.

immagine.png (14.2 kB)
2.png (17.9 kB)
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 Razputin · Jun 07, 2014 at 08:43 PM

I assume you're instantiating a circle for the bullet or some object. When stuff moves really fast in unity it can sometimes glitch through the wall. I don't think theres any work around for this. My only suggestion would be to use raycasts instead, then maybe attach some particle to make it seem like theres a bullet flying around.

Sorry thats the only question I can answer out of your three, but I hope that at least helps a little.

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 talyon · Jun 16, 2014 at 03:25 PM 0
Share

@Razputin I've never used the raycast, it seems very complicated, there is just no other way?

avatar image fafase · Jun 16, 2014 at 03:32 PM 0
Share

Raycast is simple, you have a starting point and a direction. Starting point is the bullet position, direction is its ....direction (?). Then you pass extra info if you need a distance or some layer but in your case the only extra is the RaycastHit to store some info on the hit.

avatar image
0

Answer by EtoadEzra · Sep 03, 2017 at 10:50 PM

for the glitching through walls, if you're using a rigidbody, set the collision detection in the rigidbody to continuous as opposed to discrete. You can also set the Fixed time step under Edit>Project Settings> Time, to a smaller amount.

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

24 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

Related Questions

AddComponent adds too many (C#) 3 Answers

Instantiate object in C# 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

vector3.forward doesn't work when used in Rigidbody? 2 Answers

Bullet flies away for no apparent reason. 1 Answer


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