[attach=1]
task ArcBullet(targetx,targety,arcdist,speed){
math???
CreateShotA(0,GetX,GetY,0);
SetShotDataA(0,0,speed,???,???,0,0,WHITE05);
FireShot(0);
}
math is what
First find cx and cy, where (cx, cy) is the center point of the circle. Unfortunately, I don't know off the top of my head what the math for this is but it is possible with the given information.
The initial angle of the bullet would be
atan2(GetY-cy, GetX-cx)+90.
For the angular velocity, you will first need to find the radius of the circle. Radius is easily determined with distance formula from the center to either point:
let radius = ((GetX-cx) + (GetY-cy))^0.5. After you have the radius, you can find the circumference of the circle with
let circumference = radius * 2 * 3.141592. Now that we have the circumference, we can easily determine how long it would take for the bullet to travel the whole circumference of a circle at the given speed.
let time = circumference/speed. With that time, we now know how long it should take for the bullet to turn 360 degrees as well, so angular velocity can be found with
let angVelocity = 360/time.
So to fill in some of the missing info for your code:
task ArcBullet(targetx,targety,arcdist,speed){
let initialAngle = atan2(GetY-cy, GetX-cx)+90;
let cx = ???;
let cy = ???;
let radius = ((GetX-cx) + (GetY-cy))^0.5;
let circumference = radius * 2 * 3.141592;
let time = circumference/speed;
let angularVelocity = 360/time;
CreateShotA(0,GetX,GetY,0);
SetShotDataA(0,0,speed,initialAngle,angularVelocity,0,0,WHITE05);
FireShot(0);
}
So now, all you're missing is how to get cx and cy. Maybe someone else knows the math for that, but I can't think of anything right now. As a side note, whoever decides to figure out how to get the center of the circle, make sure that what you write works with a negative arcdist as well because it is perfectly possible for arcdist to go to the other side of the line between (GetX, GetY) and (targetx, targety). Also, if you want the bullet to go counterclockwise instead of clockwise around that circle, you just need to flip the sign of angularVelocity and initialAngle would be
atan2(GetY-cy, GetX-cx)-90 instead.
EDIT: Few fixes.
EDIT2: Got bored and googled some info. I
think this works with negative arcdist as well, but it's untested in Danmakufu. Setting arcdist to 0 will give you a divide by 0 error, but any other value should work. I also added a parameter to choose whether the bullet should travel clockwise ("cw") or counterclockwise ("ccw"). Here's the full code:
task ArcBullet(targetx,targety,arcdist,speed,direction){
let chordDist = ((GetX-targetx)^2 + (GetY-targety)^2)^0.5; //Finding distance between enemy and target
let chordAngle = atan2(targety-GetY, targetx-GetX); //Finding angle from enemy to target
let radius = (arcdist^2 + (chordDist/2)^2)/arcdist/2; //Finding length of radius
let mx = GetX+cos(chordAngle)*chordDist/2 //Finding x-coord of midpoint of the chord
let my = GetY+sin(chordAngle)*chordDist/2 // Finding y-coord of midpoint of the chord
let cx = mx+cos(chordAngle+90)*(radius-arcdist); //Finding x-coord of center of circle
let cy = my+sin(chordAngle+90)*(radius-arcdist); //Finding y-coord of center of circle
let circumference = absolute(radius * 2 * 3.141592); //Finding the circumference of the circle
let time = circumference/speed; //Finding the time it takes to travel the length of the circumference with given speed
let angularVelocity = 360/time; //Finding the angular velocity to turn 360 degrees in that time
let initialAngle = atan2(GetY-cy, GetX-cx)+90; //Finding the initial angle to fire bullet
alternative(direction)
case("cw"){
//Do nothing, lol bad code.
}
case("ccw"){
angularVelocity *= -1; //reverse the angular velocity
initialAngle -=180; //turn the initial angle around 180 degrees
}
others {
RaiseError("ArcBullet expected "cw" or "ccw" for direction parameter but got " + ToString(direction));
}
CreateShotA(0,GetX,GetY,0);
SetShotDataA(0,0,speed,initialAngle,angularVelocity,0,0,WHITE05);
FireShot(0);
}