User Tag List

Results 1 to 5 of 5

Thread: Beginner question: Full directional aiming

  1. #1
    No Products Registered

    Join Date
    Jan 2014
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Beginner question: Full directional aiming

    I've been working on a defensive shooter game, real simple so far: You're in the middle of the screen, enemies come from all directions, you have to shoot them. However, I've run into some befuddling problems with direction.

    My gun, for some reason, can only fire in a few directions. This leaves blind spots a good 50 pixels wide at the edges of the screen where enemies cannot be hit until they move to almost point blank range. This is my code for the gun:

    Gun barrel:

    Code:
    Set angle to ATan2(XMouse-X( "Gun" ), YMouse-Y( "Gun" ))-90 (Quality 1)
    
    Look at (Crosshair)
    As you can see, this makes the gun point at the mouse

    Bullet:
    Code:
    Set angle to ATan2(XMouse-X( "Gun" ), YMouse-Y( "Gun" ))-90 (Quality 1)
    
    Set X position to X( "Bullet" )+((Sin(Angle( "Bullet" )+90))*10)
    Set Y position to Y( "Bullet" )+((Cos(Angle( "Bullet" )+90))*10)
    And this makes the bullet fire from the gun in the direction of the mouse.

    However, the bullet appears to only fire in specific directions - I assume 32 of them - and try as I might, I cannot figure out why. I've found half a dozen tutorials on how to do this, and somehow, they all seem to work. What am I doing differently?

    In addition, the enemies have the exact same code, except instead of pointing at the mouse, they point towards the player. However, they appear to only rotate in EIGHT directions: Upon spawning, they will move horizontally until they lie at a 45 degree angle to the player, and then change to that angle and head in a straight line.

    Any help that anybody can provide would be greatly appreciated. Thanks in advance!

  2. #2
    No Products Registered

    Join Date
    Jan 2014
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, update with a minor improvement: I discovered, more by accident than anything else, that by increasing the speed coefficient - that "*10" in the position change line - I get more resolution on the directions. By changing the bullet speed to 15, the number of directions has increased to the point where the blind spots are almost insignificant. However, obviously I can't do that for the enemies, and I haven't really solved the problem, just found a convoluted workaround. I'm still looking for help from anybody who can see the problem.

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Popcorn's Avatar
    Join Date
    Jun 2006
    Location
    Norway, Bergen
    Posts
    2,366
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    Hi!

    There are two things I think you can improve upon in your code.
    The first you need to do is to use floating point values. By default Fusion use only integers (whole numbers) while doing calculations. 3 / 2 = 1. By adding a decimal to the calculation, Fusion will calculate using floating point values instead. 3.0 / 2= 1.5.

    The second and most important improvement in this case, is to work using alterable values instead of the actual X and Y positions. In your code, since actual coordinates cannot have decimals, the object wouldn't act as you'd expect it to, as it will round each position to a whole number.

    Your positioncode should therefore look something like this:

    * Start of frame
    - Bullet: Set Alterable Value X to X("Bullet")
    - Bullet: Set Alterable Value Y to Y("Bullet")

    * Always
    - Bullet: Set Alterable Value X to Alterable Value X( "Bullet" )+((Sin(Angle( "Bullet" )+90))*10.0)
    - Bullet: Set Alterable Value Y to Alterable Value Y( "Bullet" )+((Cos(Angle( "Bullet" )+90))*10.0)
    - Bullet: Set X position to Alterable Value X("Bullet")
    - Bullet: Set Y position to Alterable Value Y("Bullet")

  4. #4
    No Products Registered

    Join Date
    Jan 2014
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much! This seems to have fixed the issue! (Though setting the initial X and Y values seems to work better when put in the bullet firing event, not the start of frame event.)

    On another note, is there a way to change a float back to an integer? I need to truncate a value and I'm not seeing a function to do that.

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Popcorn's Avatar
    Join Date
    Jun 2006
    Location
    Norway, Bergen
    Posts
    2,366
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    Int(value) does the trick. You can also use round(), ceil() and floor().

Similar Threads

  1. Beginner PATHFINDING for a 2D 4-directional game's enemies?
    By HomelessGoomba in forum Fusion 2.5
    Replies: 5
    Last Post: 8th November 2014, 09:13 AM
  2. Beginner question
    By Malama in forum Fusion 2.5
    Replies: 7
    Last Post: 7th July 2014, 10:35 AM
  3. swf beginner question
    By willow in forum SWF/Flash Export Module Version 2.0
    Replies: 6
    Last Post: 28th September 2010, 11:49 AM
  4. Beginner's Question
    By Lazor in forum The Games Factory 2 - Technical Support
    Replies: 6
    Last Post: 5th December 2009, 04:27 PM
  5. Directional Calculator Question
    By Strider in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 19th April 2008, 05:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •