Create a bubblebeam #shooting #raycasting?

hi there,

Im Creating a Game in which my player is shooting a bubble. The bubble moves Upwards if the player gives Input + The player can controll the bubble (Left, right, up, down). The bubble Should be Followed by a bubblebeam. The bubblebeam on a straightline from the player (Not Moving) to the moving bubble. Actually i Make the bubblebeam-bubbles a Child of The bubble but the Effect is that the bubbles move with The bubble but are Not straight in line.

So: any idea to create the bubblebeam straight depending on the positions?

I thought about raycasting and creating the bubblebeam on the raycast - i am not familiar with raycasting… any idea if this is possible or anything Else?

I appreciate any help!

You don’t need raycasting. You can do this with a bit of algebra (similar triangles), or more easily, use Vector2.Lerp or Vector2.MoveTowards.

Lerp will be easier if you know you want a constant number of bubbles-on-the-line, so you set the first one at (say) 0.1 of the way from player to target, the next at 0.2 of the way, the third at 0.3, etc.

MoveTowards will be easier if you want your bubbles-on-the-line to be at a constant spacing (e.g. 0.5 units apart). In that case you’ll just start with a Vector2 set to the player position, and then MoveTowards the target position 0.5 units at a time, placing a bubble at each place.