Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8714731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:40:08+00:00 2026-06-13T05:40:08+00:00

I’m making a breakout game in 3D using THREE.js and the WebGL render. I

  • 0

I’m making a breakout game in 3D using THREE.js and the WebGL render. I want to use THREE.Ray to detect collision between the bouncing ball and the platform at the bottom which can be controlled by you, but I’m having trouble.

I’ve managed to cast a ray from the platform to the ball (or other way around) but once I do that, the ball gets stuck in the middle of the screen and cannot be animated.

var ray = new THREE.Ray( platform.position, ball.position.subSelf( platform.position ).normalize() );
var intersects = ray.intersectObject( ball );

if ( intersects.length > 0 ) console.log(intersects[0].distance);

I’ve tried removing the subSelf and normalize() but that breaks the detection.

Here is the game and code can be found in script.js:

http://dl.dropbox.com/u/4531743/WebGL/Breakout-3D/index.html

If you open the console, you can see that the distance value changes if you move the panel, so that’s good. But the ball cannot be animated because at every frame it’s being set to that position.

http://dl.dropbox.com/u/4531743/WebGL/Breakout-3D/index.html#disableRay

Above is how I originally did it, just by calculating the Z position of the ball and panel and seeing if it’s bigger and is inside the panel’s width (x) coordinates, and if it is, bouncing it off.

The ball’s bouncing is just changing the X and Z coordinates by a fixed amount every frame, and if it goes too far in either direction, reversing that amount so it goes back.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:40:11+00:00Added an answer on June 13, 2026 at 5:40 am

    After some playing around I worked it out.

    var ray = new THREE.Ray( ball.position, new THREE.Vector3(ball.position.x, ball.position.y, platform.position.z).subSelf( ball.position ).normalize() );
    
    var intersects = ray.intersectObject( platform );
    
    if ( intersects.length > 0 ) {
    
        var face = intersects[0].face.d,
        dist = intersects[0].distance;
    
        if(face == 4 && dist <= 7) sizes.ball.velocityZ = -sizes.ball.velocityZ;
    
    };
    

    Basically, that way I’m always projecting a ray straight down from the ball, and if the platform is directly below it and the distance to the platform is close enough, I reverse the direction of the ball.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.