Animations Based off of Mouse Position (gravity shooter)

0 favourites
  • 8 posts
From the Asset Store
Hand-animated Sprite Base for isometric game/animation development
  • So I'm trying to create a gravity based shooter that uses the keyboard to move, and the mouse to aim and shoot. I've set up the sprites so that the gun and arm of the player follow the mouse.

    I then set the player animations to be based off of the relative position of the player to the mouse. Ex: If you're running left, but shooting right, the right animation will continue to play while you move left, since the mouse has a greater x/y then the player. So here's the code that I used to make this happen.

    However, the issue I'm running into is that there's one spot where the function gets thrown off. Everything works perfectly around the planet until the player hits this section, and then the animations suddenly get flipped. I'm assuming this is because the x/y of the mouse in this specific spot, but I have no idea how to fix it. I'm extremely new to coding thing, so I would immensely appreciate any help or advice you guys can offer!

    I can also send the file if you need it (as I can't figure out how to post the link to the dropbox file.

  • You can send a link by putting the folder in a public folder, right clicking and selecting Send Public Link. And I've tried replicating what you've done and I think I'm missing something, so I think you're going to have to post a link to the project

  • Here you go! Finally got the link working

    dropbox.com/sh/lpnx1e3uip1y93j/AABLqBLAgq7rGik9GPHNC9qra

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That is the moment where 360 degrees jumps to zero degrees. Suppose you compare to the angle towards earth.

  • Ah, I see. Well maybe I'm misunderstanding what I did, but I thought I was comparing to the angle towards earth. How would what you recommend, 99Instances2Go, look different from how I entered in the code?

  • Looked into the code. I have no idea yet, but it is lingering.

  • Okay, i had some troubles. It took me a while to realize that PlayerBox is 'rolling' over earth. This way i could not use it as a reference, and the player is mirroring its imagepoints, so the player is kinda useless. I realized when i saw the collision polygons in earth.

    So, i had to make some adjustments to make my 'idea' work. The PlayerBox's angle is now fixed to earth.

    I had some problems with the animation triggers. Player got mirrored based on keys pressed AND based on the position of the mouse. I did not correct all the animations. That is up to you. Basely you got to check if a change in animation is only triggered once. If not, add a 'trigger once while true' to the condition.

    My idea is based on the fact that you have to calculate in angles. You can not calculate with angles thinking they are just regular numbers. For that i used the expression:

    anglediff(a1, a2) Return the smallest difference between two angles

    I just evaluate the difference in angle between two imagepoints on the PlayerBox and the mouse. anglediff has no problem with angles flipping from 360 to zero.

    https://www.dropbox.com/s/wzpo30u93sesl ... .capx?dl=0

  • Thank you sooo much for your help!

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