I’m currently working on a Bullet Hell game, but I’ve run into quite the issue…
When I tried coding a frame to move towards a picked position (but continue past it as if it was flung in the direction the position was to the frame), It didn’t work as expected.
I haven’t found any topics that cover this situation.
Any help is appreciated!
1 Like
You using tween?
The frame uses Scale position or fixed?
Its inside another frame?
What is the anchor point property of the frame?
Maybe showing your code and the hierarchy of the GUI
I am using tweening, the frame uses scale, it is inside another frame, the projectile frame that I want to throw at a position has 0,0 AnchorPoint
and the code I had written was too obfuscated that I had to wipe it and attempt to start over but now I cannot figure it out.
Projectiles are stored in a folder and brought to the Objects
folder under Box
when getting thrown at a position that’s relative to the Box.
How you are getting the coordinates the projectile should use in the tween?
UDim2.new(math.random(0,854)/1000,0,math.random(0,854)/1000,0)
The minimum being 0 since AnchorPoint
is 0,0 and the 0.854 being the maximum the projectile can reach instead of 1 since this takes into account the projectile’s Size
and any further would breach the box.
At first sight I dont see any specific issue, I think you are doing it correctly.
But you said, the final position of the projectile past the given coordinates?
How are you taking in count the Size of the projectile frame?
Should be done by script too, substracting the projectile.Size.X.Scale/2
and Y too
When you just place the projectile in Objects folder inside the GUI, and change its Position Udim, for example using 0.85 and 1, the projectile goes out of the box?
Past this position is outside the Box
.
The only problem is I can’t figure out how I can code the projectile to go in the direction of that position and follow it constantly until it is deleted by a timed Debris:AddItem
function.
I would need to understand how the frame can find the facing direction to the position and follow it.
Honestly I dont know how Bullet Hell game looks like, so Im not sure the behaviour you are looking for.
You said you tried by tweening. But tween will require a specific coordinate like 0.85,0.85. But you want the projectile to follow a coordinate that will change over time? Like making the projectile following and updating its direction based on a coordinate that is constantly changing?
If thats the case, (like make the projectile follow the mouse’s cursor)
You would be needing using RunService step to constantly update the direction of the projectile
That sounds doable, but now how can I calculate the direction for the frame to follow?
Let me give you an example.
In the workspace with physical parts, to get a part moving in the direction of another part they used CFrame.LookAt()
and then started adding the part’s position by the part’s LookVector
property under CFrame
constantly so it would go in the direction of the part that the moving part was looking at.
If you would use RunService, its just updating the Position of the frame with the target coordinate, adding a specific number value to the current projectile Udim, that number would be the speed of the projectile per step, adding that “speed” each step until reaching the target Udim. Im not sure whats your target position or how you are getting it.
I should do tests in order to find the best way of doing it, and plus knowing how BulletHell looks like
I agree totally, in workspace this task is easier
Once again, the target position is defined from this:
UDim2.new(math.random(0,854)/1000,0,math.random(0,854)/1000,0)
And I see where you are going with what you are saying, but what number would the speed be. How would the speed be calculated then added or removed to the frame’s position until reaching the chosen randomized position?
I’m thinking dividing the Scale.X
and Scale.Y
by 100 to get the speed numerical then times it by the Speed
variable thats in the function that spawns these projectiles.
But I think there’s a better option that you might be aware of.
UDim2.new(math.random(0,854)/1000,0,math.random(0,854)/1000,0)
You sure this is changing over time? I mean while the projectile is moving? or it will change again after the projectile reached the target? I mean for the next projectile the coordinate will be different, but for the current one it will stay the same.
If the coordinate of the current projectile never changes during its travel, then RunService its not needed
This position never changes, this is just so the script can calculate the direction that position is in and make a frame follow that direction.
If the coordinate gotten from math.random never changes while the projectile is traveling, Im going back to the Tween approach.
You have an example of what you tried before with tweening?
I have tried calculating this before, for the first ever projectile in my game.
It did not work the way I wanted but it was a happy accident since it worked in an even better way.
(This randomly flings in the direction of the player’s (dot that the player can control) position either going in the perfect trajectory of the player or flinging right past the player).
Im starting to understand whats your goal, reminds me 2d games about tanks that shoots.
Mmh, honestly I would require to do many tests in order to get close to a possible approach…
Im sorry I cant help you any further without those tests, I never tried building a system like this one
Alright well, thank you for your time.
1 Like