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
1
Question by Cesar Belmont · Feb 28, 2011 at 07:26 PM · linerendererbounce

Line Renderer bounce

I currently have a "laser sight" on my player character using a Line Renderer and a raycast. The player character shoots balls that bounce off of walls. I am trying to achieve an effect with my laser sight that you see in most Pool games- a line that works like a laser sight, but when the end of the line comes in contact with the sides of the pool table, an angle of ricochet is displayed letting the player know were the ball is going to bounce. The picture below shows exactly what I am trying to achieve:

alt text

EDIT

I am having a bit of trouble with the implementation. The line does not seem to be reflecting or bouncing, instead they seem to be overlapped on top of each other. See code:

var hit : RaycastHit;

// these are set in start private var line : LineRenderer;

private var point01 = Vector3(0,0,0);

function Start () {

line = this.gameObject.AddComponent(LineRenderer);

}

function Update () {

line.SetPosition(0, point01); Physics.Raycast(transform.position,transform.forward,hit); if(hit.collider) { line.SetPosition(1,Vector3(0,0,hit.distance));

     line.SetPosition(2, Vector3.Reflect(Vector3(0, 0, hit.distance), Vector3.right));



 }   
 else
 {
     line.SetPosition(1,Vector3(0,0,5000));

 }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Bunny83 · Feb 28, 2011 at 08:12 PM

I guess this two things should be enough : Vector3.Reflect and RaycastHit.normal. If you want to bounce multiple times you have to raycast again for every bounce. But the accuracy is getting worse each bounce.


edit
Another problem is that your ball is not infinite small like a raycast. That means your ball is touching the wall a bit earlier. You can use Physics.SphereCast() but if your ball/projectile have not a spherical form it's getting difficult.

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 Joshua · Feb 28, 2011 at 08:41 PM 0
Share

Great answer Bunny. I was thinking about the accuracy thing, I think this would work: the part of the ball that interacts with the side is always exactly the radius of the sphere away from the center of the ball. The center will follow the same line though, but it'll hit 'earlier'. To solve this, create invisible walls away from the real walls exactly r more inside the field. Now if you make your raycast bounce of this it should show the exact trajectory of the center of your ball.

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

No one has followed this question yet.

Related Questions

How can i shoot 2D ball/bounce of wall using Raycast? 1 Answer

LineRenderer missing in build 1 Answer

Can someone help me with this line renderer? 0 Answers

Draw a line with collision 2 Answers

Making a border on a LineRenderer 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