Author Topic: Question about bullets  (Read 2867 times)

Fujiwara no Mokou

  • Hourai Incarnate
  • Oh, so this trial of guts is for ME?
    • Profile
Question about bullets
« on: June 21, 2009, 10:11:30 PM »
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

  • *
Re: Question about bullets
« Reply #1 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.

A Colorful Calculating Creative and Cuddly Crafty Callipygous Clever Commander
- original art by Aiけん | ウサホリ -

Nuclear Cheese

  • Relax and enjoy the danmaku.
    • My homepage
Re: Question about bullets
« Reply #2 on: June 21, 2009, 10:36:23 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.

Unless I've missed something, atan2 only takes 2 arguments.  I've always used it like this:

Code: [Select]
let angle = atan2(GetPlayerY() - spawny, GetPlayerX() - spawnx);
This will get the angle from (spawnx, spawny) to the player's position.
to quote Naut:
"I can see the background, there are too many safespots."
:V

Fujiwara no Mokou

  • Hourai Incarnate
  • Oh, so this trial of guts is for ME?
    • Profile
Re: Question about bullets
« Reply #3 on: June 21, 2009, 10:40:59 PM »
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

  • Ph?nglui mglw?nafh
  • Cat R?lyeh wgah?nagl fhtagn.
Re: Question about bullets
« Reply #4 on: June 21, 2009, 10:52:49 PM »
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++;

    }
« Last Edit: June 21, 2009, 11:01:30 PM by Iryan »
Old Danmakufu stuff can be found here!

"As the size of an explosion increases, the numbers of social situations it is incapable of solving approaches zero."

Fujiwara no Mokou

  • Hourai Incarnate
  • Oh, so this trial of guts is for ME?
    • Profile
Re: Question about bullets
« Reply #5 on: June 21, 2009, 11:04:08 PM »
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.

Thank you.  That's exactly what I was looking for.

Drake

  • *
Re: Question about bullets
« Reply #6 on: June 21, 2009, 11:26:14 PM »
Oops, I was combining atan and atan2, sorry.

A Colorful Calculating Creative and Cuddly Crafty Callipygous Clever Commander
- original art by Aiけん | ウサホリ -

Fujiwara no Mokou

  • Hourai Incarnate
  • Oh, so this trial of guts is for ME?
    • Profile
Re: Question about bullets
« Reply #7 on: June 22, 2009, 03:15:42 PM »
Uh, one more problem. I was trying to load a few other people's scripts in Danmakufu so I could see how it works, etc.  But every one that loads has the same error coming up.  Something about "lib\SHOT_REPLACE\shot_replace.dnh"

Can anybody help?

Helepolis

  • Charisma!
  • *
  • O-ojousama!?
Re: Question about bullets
« Reply #8 on: June 22, 2009, 03:41:12 PM »
Most people are using the Shot replace textures for their shots.

Download it here in this thread: http://www.shrinemaiden.org/forum/index.php?topic=345.msg9261#msg9261

And place it in the root of your Danmakufu. You should be able to run majority of the scripts.

Fujiwara no Mokou

  • Hourai Incarnate
  • Oh, so this trial of guts is for ME?
    • Profile
Re: Question about bullets
« Reply #9 on: June 22, 2009, 04:58:52 PM »
Thanks alot Helepolis, you were right.