Animations Based off of Mouse Position (gravity shooter)

Get help using Construct 2

Post » Sat Jun 25, 2016 10:10 pm

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.

Image


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.

Image
B
4
S
1
Posts: 4
Reputation: 308

Post » Sat Jun 25, 2016 10:41 pm

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
B
13
S
2
Posts: 15
Reputation: 1,575

Post » Sat Jun 25, 2016 10:44 pm

Here you go! Finally got the link working :)

https://www.dropbox.com/sh/lpnx1e3uip1y93j/AABLqBLAgq7rGik9GPHNC9qra?dl=0
B
4
S
1
Posts: 4
Reputation: 308

Post » Sat Jun 25, 2016 11:14 pm

That is the moment where 360 degrees jumps to zero degrees. Suppose you compare to the angle towards earth.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Jun 25, 2016 11:43 pm

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?
B
4
S
1
Posts: 4
Reputation: 308

Post » Sun Jun 26, 2016 12:25 am

Looked into the code. I have no idea yet, but it is lingering.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Jun 26, 2016 12:13 pm

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
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Jul 17, 2016 7:25 pm

Thank you sooo much for your help! :)
B
4
S
1
Posts: 4
Reputation: 308


Return to How do I....?

Who is online

Users browsing this forum: sean080, TRMG and 39 guests