Display path of the ball like bubble shooter

I would like to draw the line just like bubble shooter in gdevelop.
I am unable to draw line from starting ball . I need to display full path.
Can some one help me with code

1 Like

Any one has solution to this?. It will be great help

Next time come here with something harder

Just kidding i am sitting on it almost whole day
And its 3 am here

Yo there

I made enough events so you have idea how to make more lines
IDK how to control number of rays/lines

And what you have here makes 3 of them
Also i have no idea how to prevent line from going trough eventual balls
So for example if line would reach balls on top
Then stop line and stop from drawing more lines
I guess it would be something like casting against balls them self
Yet i am not sure how to do it

Now above method will work like deflecting ray from each wall
EVEN ones on top

YET i am not sure you actually need it
Maybe you need only horizontal checks?
Not deflecting from top or bottom wall

Then 1st option is to disable these events or delete them

2nd option is well pretty much the same
Just specially dedicated for it event
BUT only for 2 lines but by now you should understand how to make 3rd or more

@Keith_1357 @MrMen
I am pinging you both for few reasons
1st of all 90% of you see here i got from post i found today and authors was always one of you
Keith your post about how you found formula to detect point of collision between rectangle and circle helped me here to understand few things
MrMen you i remember helped me with minimap roatation
Where i needed to draw each platform wall with shape painter
So it can rotate properly

Next i lack the knowledge to go any further with it to do

  • dynamically add lines
    Idk how to shove in there “repeat” event
    I mean i know how to use it to repeat something like spawning objects
    But this is too complex for me
    I would assume array here would be the key but i suck with arrays so well here i ask you two for help
  • Aside from things i mentioned to Gurulakshman idk how to to do
    I have no idea how to detect from which side of wall IF wall is rotated detect raycast impact point
    Since there are 3 methods to detect raycast or more like 3 ways to deflect ray from walls

1 is only horizontal
2 only vertical
3 would be per angle of object
4th would be same as 1 and 2 just combined so i am not counting it

BUT if it would be possible to detect from which side impact is done on rotated wall then then that would be fully functional raycast covering all kind of games

I gonna explain here a little bit so it is easier to understand what you are looking at

Difference between link below and then one above is
In here top wall angle is 109
Where bottom one is -90

And you spawn little above where you would spawn in link above

Now

1st raycast should not have anything that is not obvious
However 2nd raycast formula

ObjectAngle + AngleDifference(ObjectAngle, Player.AngleToPosition(RayX, RayY) + 180)

I got literally from bounce extension
But to my understand basically it is this
I mean image
https://wiki.gdevelop.io/gdevelop5/extensions/bounce/explanations/

That raycast offset group
We are checking if point where ray did hit wall is inside the wall
BUT we are checking 4 variants + - 1 each direction
So 1st event from top Checks if ray is inside wall but -1 x so one pixel to the left
If so in action we set RayOffsetX var to 0.01
If that point -1 pixel to the left is inside the wall means there is wall on the left and not right
And that RayOffsetX is there so we move next starting position of raycast to not start inside wall and auto detect wall
Where 0,01 instead of 1 to make it as accurate as possible
You can deduce how other 3 events work

Sub events here are for detecting from which side of wall raycast did hit
Yet it is only for casting ray if wall was not rotated
And just deflecting it based on angle of ray itself
Where in this case we are deflecting based on angle of wall ray hits

Just to be clear
AGAIN
90% of crap i made here i learned from both of you today reading your posts
And well since im here
You two already contributed more than me to this events
Will you help more or not in my eyes you two are authors of what is above
Respect

1 Like

Here’s what I’ve been working on. It uses a while event. As always, be careful because when using the while event you can get stuck in an infinite loop and have to close the preview. It seems fine as written but it wouldn’t hurt to test more and maybe have a failsafe of some type.

Source: Click the green [Code] button and [download zip] extract and open JSON file.
https://github.com/doug13579/gdevlop-bubble-path-draw

There are extra files in the asset folder. I started online and after downloading, I made changes. It’s not perfect but close.

try me: click to aim and release to shoot. Click again to start over.
https://gd.games/keith_13579/missions

Here is the scene.

Variables

group
image

Events

I used a red hitbox for the walls because I didn’t know how to compensate for the ball. The ray is cast from the center so the test wall is half the width of the ball.

It draws the path as the ball moves which causes a little lag. It’s just for testing.

I added lastSide because it was acting weird. The X,Y created by the ray cast was too close to the wall, so the next time a ray cast was sent it was detecting the current wall. It saves the X of the wall, so it can ignore the last wall.

Edit, there are some scene varaibles. I started with Global beacuse they’re easier to setup online. Some of the variables are no longer needed. I didn’t feel like cleaning it up.

1 Like

HI @ZeroX4 thanks for the code.
Can you send me the whole project in github . I can refer whole code. I am new to gdevelop

I suggest you go with Keith’s solution instead of mine

If you look at what Keith done (he already added github link)
And you still somehow prefer mine then i gonna upload it

But i hardly see how you may want mine over Keith

I always wanted to make biliard game
Only thing preventing me was how to make this line with raycast
That is why i went into this problem to find out a way
But your method looks A LOT more streamlined than my idea

And as for how to account ball size and not use additional hitbox wall with half size of ball i guess this is what you need

Where assuming your ball is 6 pixels radius (so 12 height/width) like in your last action
You would put there 6.01 instead of 0.01

BTW if its not array
How is it not overwriting all variables?
Like each var is its own thing?
I was sure you need array for that to prevent it from happening

And like always let me repeat myself
THX

1 Like

I made a version awhile a go that works in all directions. IDK if it’s my most recent version.

Source
https://github.com/doug13579/gdevelop-bounce-calculator2

Try me, it uses a slider instead of aiming.
https://games.gdevelop-app.com/game-24de8857-ed76-4e5b-959d-92d22f9f9ea1/index.html

I’m on my phone. So, I didn’t look at the current code but you’re welcome to use anything in it or my github.

I tested it and it’s a bit flawed. It works most of the time. IDK what the code looks like. It’s been awhile. The tank is also dragable.

Thx Keith i gonna try both versions for sure

But this still don’t answer my question

I really was sure it requires array to not overwrite values
Yet you are not using array
So how come each line have its own like set of variables?

Or am i missing something?

Each line gets drawn on the painter. No need for an array. It uses a while event to loop until the ray cast hits something other than a wall like the top or a ball.

This was the inspiration for the 2nd version.
https://stackoverflow.com/questions/45154176/calculate-angle-change-after-hitting-a-tilted-wall

More detailed
https://www.geeksforgeeks.org/laws-of-reflection/

1 Like