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 vipvex · Dec 30, 2012 at 06:27 PM · anglebulletprojectilebounce

Determining the angle of a projectile collision.

I am trying to make a projectile that when colliedes with a surface at a 45 degree or lower will bounce and keep moving. I was trying to implement that with this code, but sadly I can't get it to work.`if (bounce){

     var angle = Vector3.Angle(collision.contacts[0].normal, transform.forward);
     Debug.Log(angle);
     if (angle < bounceAngle){
     
         transform.position = collision.contacts[0].point + Vector3(0, 1, 0);
     
     
     }else{
     
         bounce = false;
     
     }`
Comment
Add comment · Show 4
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 gardian06 · Dec 30, 2012 at 06:31 PM 0
Share

EDIT I don't see where you set bounce to true. I see where you set it to false.

avatar image vipvex · Dec 30, 2012 at 07:32 PM 0
Share

it's before this code sorry. I'm sure the problem is in the angle some were but i can;'t figure it out

avatar image gardian06 · Dec 30, 2012 at 08:01 PM 0
Share

shouldn't it be if(angle>bounceAngle){, and why are you adding 1 in the positive y-direction shouldn't you be reflecting it across the plane perpendicular to the collision?

avatar image $$anonymous$$ · Jan 17, 2013 at 06:33 AM 0
Share

Hi, I believe, we look for the same solution. Here I added two pictures, to better representation. As far as I understood here, also no solution was found here. Please help us community.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by voodoo · Dec 30, 2012 at 07:42 PM

Off the top of my head, give this a try:

     // Reflect the trajectory of the contact
 var reflected : Vector3 = Vector3.Reflect( transform.forward, collision.contacts[0].normal );
     // Compare how alike the reflection and the original direction are
 if ( Vector3.Dot(reflected, transform.forward) > 0.5 ) {
     // Do bounce logic
 } else {
     // Do not-bounce logic
 }

See: Vector3.Dot, Vector3.Reflect

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 vipvex · Dec 30, 2012 at 09:37 PM 0
Share

Thanks this worked :D! But now i need to make the projectile move perpendicular to the surface it hit but keep it's trajectory.

avatar image voodoo · Dec 30, 2012 at 10:14 PM 0
Share

So you want it to slide along the surface it hits, or bounce off in the same direction? $$anonymous$$eep in $$anonymous$$d we already have our 'reflect' variable that gives you the direction of reflection. ;)

avatar image vipvex · Dec 30, 2012 at 10:46 PM 0
Share

When I assign reflected to the transform.rotation it always starts moving in the global z axis only. How do I fox that?

avatar image voodoo · Dec 30, 2012 at 10:49 PM 0
Share

Try using: transform.LookAt( transform.position + reflected );

I think that should do it.

avatar image vipvex · Dec 30, 2012 at 11:08 PM 0
Share

Thank you :)

Show more comments
avatar image
0

Answer by Drakmyth · Dec 30, 2012 at 08:30 PM

It's a little hard to tell without more code, but the first thing I notice is that your first line there is measuring the angle between the forward vector of the projectile (assuming this script is attached to the projectile) and the normal of the collision. If I'm not mistaken, the collision normal is perpendicular to the surface, which means the angle you want is (90 - angle), not angle itself.

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 gardian06 · Dec 30, 2012 at 09:19 PM 0
Share

with the boolean check given on line 3 yes the measure should be the angle between the normal, and the forward, but if the OP reverses the boolean check then the angle measure can be maintained.

what gets me is what is going on with the + Vector3(0,1,0). what does moving it 1 unit along the positive y-axis have to do with reflection.

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

11 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

Related Questions

Bounce into the air 1 Answer

Float to angle coordinate? 1 Answer

Shooting Script Bullet Doesnt Fire 2 Answers

Calculating a projectiles angle required to hit object. 2 Answers

Change bouncing angle with touching speed 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