~Hakurei Shrine~ > Rika and Nitori's Garage Experiments
Question about bullets
Fujiwara no Mokou:
In the examples given by Blargel, when I used "GetAngleToPlayer" in "CreateShot01(GetX, GetY, 3, GetAngleToPlayer, RED01, 10);" it is a function that gets the current angle from the boss to the player. But does NOT get the current angle from the spawning point of the bullet to the player so the bullet will only aim at the player if it is spawned directly on top of the boss (and thus at the point (GetX, GetY)).
This is a problem for me, as I want to know what I can use to get the bullet to aim at the player from the spawning point of the bullet from ANYWHERE on the screen, so that I can make it aim at the player from anywhere, and not just from the boss.
This would be very helpful for me, as I also want to include this in the function "CreateShotA" AND "SetShotDataA". This way I can spawn and control bullets that actually make them aim at the player if I make them spawn somewhere at a coordinate other than where the boss is. If anyone can help me with this problem, it would very much appreciated.
Also, an example would also be very much appreciated.
Drake:
atan2(y of target, x of target, y of point, x of point);
so
atan2(GetPlayerY, GetPlayerX, spawny, spawnx);
will take the angle from spawny/spawnx to the player, assuming that's where you spawn the bullet.
Nuclear Cheese:
--- Quote from: Drake on June 21, 2009, 10:21:59 PM ---atan2(y of target, x of target, y of point, x of point);
so
atan2(GetPlayerY, GetPlayerX, spawny, spawnx);
will take the angle from spawny/spawnx to the player, assuming that's where you spawn the bullet.
--- End quote ---
Unless I've missed something, atan2 only takes 2 arguments. I've always used it like this:
--- Code: ---let angle = atan2(GetPlayerY() - spawny, GetPlayerX() - spawnx);
--- End code ---
This will get the angle from (spawnx, spawny) to the player's position.
Fujiwara no Mokou:
Erm, either that's not what I'm looking for, or I don't know how to use it.
Let's say this is what's in my @MainLoop
@MainLoop {
SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 24);
if(frame==60){
CreateShot01(150, 120, 3, GetAngleToPlayer, RED01, 10);
frame = 0;
}
frame++;
}
Now, how would I get "CreatShot01" to aim at the player? Obviously, it's the "GetAngleToPlayer" that's making it shoot off away, because of it's coordinates from the BOSS to player. But what can I use in place of it so that the bullet will aim directly at the player from the spawning point of the bullet? Maybe an example of the entire '@Mainloop' would clear things up for me...
Iryan:
The command SetShotDirectionType(PLAYER); will make danmakufu measure the angle in angle towards the player rather than towards the right hand side of the playing field. Call it before firing the bullet and then fire the bullet at an angle of 0. Call SetShotDirectionType(ABSOLUTE); afterwards to return the angle measuring back to normal.
The alternate method would be to use the atan2 command to get the angle between the position of the bullet and the position of the player.
Let's say the bullet starts at the position (x|y).
atan2(GetPlayerY - y, GetPlayerX - x) will give you the correct angle.
I prefer SetShotDirectionType, though, because you can create a bullet using CreateShotA, tell it to move a specific way with SetShotDataA and then later to aim directly at the player by calling SetShotDirectionType before and after one instance of SetShotDataA.
Edit: Here comes the main loop example that was asked for:
@MainLoop {
SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 24);
if(frame==60){
SetShotDirectionType(PLAYER);
CreateShot01(150, 120, 3, 0, RED01, 10);
SetShotDirectionType(ABSOLUTE);
frame = 0;
}
frame++;
}