From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a really basic alleyway for a beginner

First, calling your file xxx.jpg when it really is a bitmap is not a cool move.  Add that to your lessons learned.

 

Without looking at your code, it sounds like a classic collision detection problem.  Your object takes a large step and lands inside the boundary.  You check, see a collision and reverse the velocity.  In the next step it doesn't make it outside so you detect another collision and reverse the velocity again.  Now you have effectively captured your object.  One solution is to kick the object to the boundary along with reversing the velocity to fix the penetration problem.

0 Kudos
Message 11 of 24
(1,180 Views)

Hello Darin.K, I think I did what you told me by multipling the velocity by -1 if the ball is near the line by using the case structure that I inserted but is still not working.

 

And how can I make the velocity constant?

 

Thank you for your time.

0 Kudos
Message 12 of 24
(1,139 Views)

What is happening is that the circle is hitting the top or bottom of the line and you are reversing the x velocity but not the y velocity.  You need a little more sophistication in your collision resolution.

 

You can make the velocity constant by replacing the 'Generate White Noise' vi with a constant.  Just delete the VI, right click on the shift register and select 'Create Constant'.  In the array just enter two values for x and y speed.

0 Kudos
Message 13 of 24
(1,110 Views)

Echo Wolf2 wrote:

And how can I make the velocity constant?


You can generate a constant velocity random xy-speed array by forming a complex number with R as the desired constant speed and rand(0..1)*2pi as theta. Typecasting it to a 1D DBL array will get you the speed array compatible with the rest of the existing code.

0 Kudos
Message 14 of 24
(1,104 Views)
Yes, your algorithm is falling a part because when the ball approaches from an end, the line is penetrating.  Actually the problem is that you are looking at it as a line.  As I said earlier, you need to treat the brick and thus its collision boundary as rectangles.  When the center of the ball is detected to be within the collision rectangle then you invert the appropriate velocity direction.  You may need to do a few more calculations to determine which boundary of the collision rectangle has been breached so you know which is the correct velocity direction to negate.
0 Kudos
Message 15 of 24
(1,101 Views)

  I tried seperating the coordinates of the "brick"but I am not able to fix the problem.

 

 I think that I am either not entering the coordinates right  and am unable to change the speed with that

or(which is my first choice)  I am unable to to differentiate between the x and y velocities.

 

Please can you help me solve the problem.I believe that I made the velocity constant but neglected changing its direction when it hitts the upper part.

 

Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.

 

 

0 Kudos
Message 16 of 24
(1,069 Views)
 
0 Kudos
Message 17 of 24
(1,068 Views)
Sorry,but I was unable to post the previous msg with the attachments
0 Kudos
Message 18 of 24
(1,059 Views)

You really digging yourself into a hole here. You are making these elaborate constructs to duplicate what the existing "in range&coerce" already does and then you are adding complicated stacked cases to repeat what the original simple FOR loop already does. You are actually breaking the code, because your new booleans are scalars and thus always apply to both x and y, blurring specificity.

 

All the small FOR loop does is invert zero, one, or both of the two speeds and that's all it needs to do. Your additional case structures don't change that. If you need to handle more specific conditions, manupulate the boolean array before entering the loop. All that extra garbage does NOT add functionality. Also, there is a primitive for a multiplication with -1, it's already there. No need for diagram constants.

 

At this point you should also make yourself familiar with basic debugging techiques: highlight execution, single stepping, probes, conditional probes, retain wire values, etc.. Then you  simply watch what values appear and what they should be, and adjust the code accordingly.

 

 

(As I already mentioned, I would recommend that you try to solve it using an intensity graph instead. The code would be much simpler.)

0 Kudos
Message 19 of 24
(1,041 Views)

Here is my alley way, brix, pong, bouncing ball. Attempt. I never finished it but i had started the most important part. the ball and paddle. I've dont this in C, pascal and Visual Basic. So when i tried to do the logic for the edges i just used c style code. The reason i did the degre out is so i could have the ball bounce at different angles. I never added the code for that. Maybe some of this will help? or make things worse 😉

 

p.s. snipet always does this to me? you may need to fix the broken wires, not sure why snipet does this.

 

p.p.s okay use the vi instead i guess 😞 it removed my pane:mouse movement from the event box? and the property nodes to the picture box? oh well.

 

 

ball_bounce.png 

- A minute saved is a Minute earned!
0 Kudos
Message 20 of 24
(1,013 Views)