Sprite movement 8 Dir troubles

0 favourites
  • 8 posts
From the Asset Store
Run and Jump in 3 Dimensions! Take your platformer to the next level!
  • There doesn't seem to be a lot of documentation on this. I'll use an examples on this. Any I've found deal with 1 sprite top down and the 360 rotation. Do I really need dozens of events to cover 8 dir movement with say for example one of the tank sprites from the sprite pack? Even doing so with that there seems to be issues with movement when multiple keys become involved.

    I played with the tank sprites a bit to see what i could accomplish as far as the events and the animation/movement system but it's buggy at best when dealing with a full 8 directions. Something tells me it's more to do with me, but again there isn't much reference I've found.

    So far it seems I'd need minimum of 16 events and 16 animations to accomplish this. (and it would be buggy dependant on what key combinations you may be using to control certain diagonal movements.)

    Any thoughts, insight or various reference would be greatly appreciated.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • OMG That's simpler then I would have imagined. Sorry bout the vagueness of the question. After re-reading it I had to stop and go uhhhhh. Again that's exactly what I was talking about. I really appreciate the response, thanks again! :)

  • I've been looking for a way to have smooth transitions in my player's 8 way movement. The problem is I need to put some frames in between each of the 8 directions. I'd probably need 32 total (8 directions plus 3 frames in between them).

    If R0J0hound or someone else could explain what each part of this code is doing so I could adjust it for my needs, it would be greatly appreciated.

    The code is int(((Sprite.8Direction.MovingAngle+360+22.5) %360)/45)

    Much thanks.

  • So the MovingAngle is the current angle, but it could be negative, so you add 360 to ensure it isn't. I'm assuming you add 22.5 to force it to choose one higher (a rounding effort) and then you mod it by 360 to get it in range (0-359). You divide it by 45 to see which animation you should be showing because there are 8 directions, and 8*45 = 360.

    If you really want 32 animations you'll need to divide by 11.25, and instead of 22.5 you'd add 5.625

    (I could be totally wrong too!) BUT I am right in saying your game and your hero sprite are wonderful!

  • Sprite.8Direction.MovingAngle is a value between -180 and 180.

    (Sprite.8Direction.MovingAngle + 360) % 360 converts it to a value between 0 and 360

    360 / 45 = 8

    int(angle / 45) converts an angle between 0 and 360 to a number between 0 and 8

    int((Sprite.8Direction.MovingAngle + 360) % 360) / 45

    gives you this:

    <img src="https://dl.dropbox.com/u/8367729/construct/pics/8dir1.png" border="0" />

    Frame 0 would be between 0 and 45 degrees, really you want frame 0 to be between -22.5 and 22.5 so you want to rotate the entire thing 22.5 degrees. That's where the 22.5 comes from:

    <img src="https://dl.dropbox.com/u/8367729/construct/pics/8dir2.png" border="0" />

  • I would absolutely love to see more threads like this. Explaining the equations, and seeing the diagram Rojo put up, makes understanding the math a little easier. Math gives my brain the hiccups. Once I can visualize what is actually happening, it starts making sense.

  • How do you do this with mobile touch controls rather than keyboard? Any tricks to do simple one action?

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