User Tag List

Results 1 to 9 of 9

Thread: Mouse controlled gun

  1. #1
    No Products Registered

    Join Date
    Jul 2010
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mouse controlled gun

    I have a mouse controlled aim, eight-direction character and a gun which shall be controlled like the flash game black. If I do User clicks left button - shoot bullet from gun towards aim it doesn't work. It only works with a keyboard button.

    And how can I make the gun always look towards the aim? like spinning. Mine just moves a bit.

  2. #2
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module
    RickyRombo's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere between here and there
    Posts
    3,167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse controlled gun

    360 Degree shooting is what you're looking for. You'll need to set the angle rather than the direction of the gun, and you won't be able to use the "Launch bullet" action - rather, you'll have to use sin and cos to customize the movement of the bullet, and use "Create" to create the bullet and set the angle of the bullet to Atan2(Y("Bullet")-YMOuse, XMouse-X("Bullet")) and use that for your sin/cos movement.

    There's a tutorial by Dines in the articles section that relates to Sin/Cos

  3. #3
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse controlled gun

    For the mouse button trigger, this is something that gets a lot of people early on - when you use the Mouse movement, the object is thought of as controlled by Player 1, and so the "User clicks" events aren't activated - those are for actual clicks by the Windows mouse cursor. You can either use the "Player 1 presses Fire 1" events in place of them, or change the mouse movement entirely and use an event to always set the cursor to the position of the mouse:

    Always -> Set X position of cursor to XMouse
    -> Set Y position of cursor to YMouse

  4. #4
    No Products Registered

    Join Date
    Mar 2009
    Posts
    412
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse controlled gun

    My first game was like this aswell .. I think. I have not really played Black before.



    Sadly, I ended up with too many issues, specially about saving with ini, so I gave it up.. Anyway, maybe you can use some of the formulas I have (which I most likely got from David!).

    ------------------------------------------

    I googled Black now, and I get how it works. If you turn my game a little around, it is the same. I can try make a quick reply on how I think it would work, using the sources from my own game.

    Because Im writing while I read through my project, I change my mind a lot. And tbh I gross at the formulas I have been using! I think the easiest is to first make an object that will replace your cursor, like the red aim I have if you view full size on my screenshoot. Call this object Aim, and remember to set the Hot Spot in center.

    [b]Always[/b]
    - Set Y Position of Aim to YMouse
    - Set X Position of Aim to XMouse

    Scratch this, move on..


    Then its the shooting. I suppose you already have a player object and a bullet object... Bah, here comes hell. On your bullet object, add a few Alterable Values:
    X Pos
    Y Pos
    X Speed
    Y Speed
    And give it a Bouncing Ball movement.
    ...
    To be honest, Im starting to not know what Im doing anymore. Fix the Alterable Values as I said, and the bouncing ball movement as I said. Also, set Action Point of Player to center. Then add these events:

    X Position of Aim is Greater or Equal XActionPoint("Player")
    - Set X Position of Aim to XMouse
    - Set Y Position of Aim to YMouse
    Set these events under the bullet:
    - Add X Speed ("Bullet") to X Pos
    - Add Y Speed ("Bullet") to Y Pos
    - Set X Position of X Pos("Bullet")
    - Set Y Position of Y Pos("Bullet")
    And at last, under player:
    - Set Angle of Player to 90+ATan2(X(Player")-X("Aim"),Y("Player")-Y("Aim")

    X Position of Aim is Lower XActionPoint("Player")

    Copy all the events, but on the last, add minus infront of 90:
    -90+ATan2(X(Player")-X("Aim"),Y("Player")-Y("Aim")


    Then, shooting:
    User clicks with Left Button
    Create Bullet at 0,0 from Player
    (Add these events under the bullet event)
    Set X Pos to X("Bullet")
    Set Y Pos to Y("Bullet")
    Set X Speed to CoS(Angle("Player"))*35
    Set Y Speed to Sin(Angle("Player"))*-35
    Start
    Look at (0,0) from Aim

    .. I think you are on a good way if you did this right. You still need to find a clever way on your player moving tho! Someone else got a better way for that, I stick to platform style.

    I hope I was to some help, somehow.. Sorry for messy answer, but its hard.. at least it really was for me

  5. #5
    No Products Registered

    Join Date
    Jul 2010
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse controlled gun

    X Position of Aim is Greater or Equal XActionPoint("Player")

    Won't work.

    Gives the error:
    Cannot understand the second expression.
    Please correct it or click CANCEL.

  6. #6
    No Products Registered

    Join Date
    Mar 2009
    Posts
    412
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse controlled gun

    Is your aim object named Aim and your player object named Player?

  7. #7
    No Products Registered

    Join Date
    Jul 2010
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse controlled gun

    Yes

  8. #8
    No Products Registered

    Join Date
    Mar 2009
    Posts
    412
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse controlled gun

    Well, try do it manually.
    New condition: Right click on the Aim object, mouse over Position and select Compare X Position to a value. In the comparison method, select Greater or Equal, and then hit Retrieve data from an object. In the popup window, right click on the Player object, mouse over position and hit X Coordinate of action point.

  9. #9
    No Products Registered

    Join Date
    Mar 2009
    Posts
    412
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mouse controlled gun

    I tested out the code I gave you, and its not working. It needs some minor changes.

    Take a look at my attachment here:
    http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=201678&#Post201 678

    It should have the right events.

Similar Threads

  1. Mouse Controlled BUG
    By imothep85 in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 2nd September 2012, 04:59 PM
  2. Mouse Pointer & Mouse controlled obejct
    By danjo in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 28th April 2012, 12:17 AM
  3. Mouse controlled movement
    By ineke in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 16th January 2011, 04:35 PM
  4. Problems with Mouse Controlled
    By evilpantsmaster in forum The Games Factory 2 - Technical Support
    Replies: 4
    Last Post: 10th January 2008, 12:24 AM
  5. Mouse click w/mouse controlled objects??...
    By WillBellJr in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 30th July 2006, 02:27 AM

Posting Permissions

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