Character controlled by WASD pointing towards mous

0 favourites
  • 15 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • So I'm trying to make a 2d game where you control the character with WASD but he points towards where the mouse is. How do I do that?

    I've checked out the "Diablolike-movement" guide and thats almost what I want. Just that I want the sprite to look towards the mouse and move with WASD, not by clicks.

  • Well, moving the character and facing it toward mouse are 2 different things so i think you have no problem with that.

    Once you have the wasd moving, make the following action:

    System, on Every tick, Sprite(character) Set angle toward (Mouse.X, Mouse.Y)

    NB. You should have added mouse plugin to use that Mouse.X/Y expression

    Hope that helps ya

  • But doesn't that make the result that's in the "Ghost shooter" example? Because that's not what I want. Here's a little pic example:

    <img src="http://abitsal.net/1.png" border="0" /><img src="http://abitsal.net/2.png" border="0" /><img src="http://abitsal.net/3.png" border="0" />

  • You would set different animations for each way he is looking. then sya that when the mouse is between X degrees he is using the certain animation set to looking at that direction.

    hope that helped!

  • I'm a bit noobish on this so I understood like 1% of that :P

    Can my make an quick .capx file with comments explaining a bit further? That would be very helpful!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ill try to explain this

    You have conditions and you have actions

    It works like: If (condition), then (action)

    In your case i would do the following

    Attach an empty sprite to the position of the character

    Set action that Sets angle toward Mouse.X/Mouse.Y

    Now you have the emty sprite rotating toward the mouse

    If the 8 directions of the character are 8 different animations, then set the following event:

    IF: System, Every tick /THEN: "Character sprite" Set Animation

    and in Animation tipe "round(EmtySprite.Angle/45)"

    that makes the angle from 0 to 44 = 0, 45 to 89 = 1, 90 to 134 = 2 and so on.

    So now when the angle is within 0 - 44 you get 0, which is animation 0

    Hope you understand it

    BTW i dont know if thats the best way but i'm just trying to help.

    Cheers

  • Didn't work :(

    dl.dropbox.com/s/b3qupmzj2twr8zq/test.capx

    What did I do wrong? Can you edit and add comment on where if you find the error??

  • Yup my bad

    It works with frames but don't seems to work with animations

    Anyways here is the solution... its kinda clumsy but still works

    dl.dropbox.com/u/19082408/123.capx

    I have started it you should finish the rest

  • Thank you so much!

    Now I finally understand :D

  • Now my next question (don't know if it's possible at the moment):

    I tried to make him fire bullets when holding down left mouse button. Bullets are spawning correctly (1 per 0.35 sec).

    But when I tried to make them go at different directions for when he's facing another way, they just change everytime my mouse moves and character switches animation.

    I added "angle of motion" on every direction event, this is how the event sheet looks like:

    <img src="http://abitsal.net/event.png" border="0" />

    Download a .capx here if you're OP:

    dropbox.com/sh/c08d30hn4j6azci/i0AgKCgZYy

  • You can try to make a condition "On object created" for the bullets

    That way the bullets direction will be set once when the bullet is created

    Hope that is what u ment

    Cheers

  • Yes it is!

    Thank very much!

  • Here's a more compact way of doing the animations (what Pakost was getting at before):

    8dirAnimAndShoot.capx (r119)

  • Nice

    I always knew i lack some math knowledge :)

  • Thanks is very useful. <img src="smileys/smiley17.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)