Change object animation (top-down style) with mouse position and possible "bug"

You’re welcome. I believe in simplicity. The fewer events you use, the easier it is to debug when something invariably goes wrong.

Me also i just forget about other ways to do stuff that would actually work so i just go with 1st thing that comes to my mind that would work

Also do you have any idea why it is 0 to 180 then -180 to 0 and not 360 degree?

1 Like

I don’t know why they use 0 to 180 and -180 to 0. There must be a reason. IDK if it works better with other functions or formulas? Even if it went from 0 to 360, there would still be a crossover when 0 and 360 meet. There’s probably a way to use sin() or some other function to get the direction easier. Time to Google.

I think you didn’t get my question
I was asking why it is NOW 180 -180 and not 360 like everyone are repeating

I never did stuff with angles this was my 1st time
But from day one i sit on gdev discord i remember for angles 270 0 90 180 top right down left
Just like everyone says

And everybody repeated it like mantra to any1 who did need to determine angle of something
I even seen it many times on forums

And when i wanted to do something with angles only thing that saved me from hours of confusion was i wanted to print angle with text object because i was not solving here my issue but another user from discord
So i wanted to show him in which position to player what angle mouse will have

And if not for that fact i would not print angle and simply try to do that 4 animations with 360 degree and wonder for hours why it does not work

So again i don’t care why they switched i bet there is a reason and that is fine with me
I wonder why everyone repeat 360 and it is 180 -180
Did i miss that transition?
Or maybe 360 degree is for something else?
I am simply confused here

It’s like in few years kids will ask why ppl call meta facebook?
I doubt any1 will care why they changed name
But question is why everyone around call it one thing when it is called another

And i’m kinda in same situation i don’t care for reason why it changed
I care did i miss that change and was it not long ago?
Why ppl still refer to it as 360?
Are they same things or angle to object is 180 -180 while 360 is reserved for something else?

I wish I had the answer. I don’t do many calculations with angles. I just know when it’s something like the angle of a sprite it’s 0 to 360 but things like AngleBetweenPostions it’s -180 to 180. I don’t know if it’s because it’s a reference. I really dont know. It confuses me everytime. I usually need to write or draw it out or check the value to figuire out the angles.

1 Like

Hi, I’m trying to program the same behaviour, to change the animation based on the position of the mouse.

I set it up as you described, but the change is not happening.
Any clues?

I believe the issue was the way angle between position works. It’s probably easier to set it up if you set a text object to your MouseAngle variable.

Instead of 0 to 360, it returns - 180 thru 180

You would need to check for those values.
Right up would be -45, left up - 135

See the image on this post

Angles for 6 directions


Move mouse around player look at head

Angle position from center
image

Thank you, @Keith_1357 and @ZeroX4!

I got it working.

Any idea how to play the animation in reverse when the angle of movement is opposite to mouse angle? :sweat_smile:

1 Like

I’m not sure what you mean.

I mean, now I have a character that is animated according to the mouse angle from the character, so if I point the mouse top-right, the character will look top-right, but if I walk bottom-left at the same time the animation is still for going in the top-right direction. So I’m moving backwards, but the animation shows the character going forwards.

I’m still confused. Are you moving with the keyboard or joystick (it doesn’t matter which one) then what is the mouse for? Is it for aiming? How do you decide which takes control? You need to add some form of logic to switch between the 2 methods or maybe only aim the weapon or use an arrow or crosshairs.

What exactly is happening in your project? What is it about?

It’s an isometric view. I still haven’t decided on how I want the controls to work exactly, I’m still prototyping, but what I’ve got so far is this:

  • I can move the character with keyboard (WSAD) or left gamepad stick and the character is animated depending on the direction of the movement.

  • On right mouse click, for gun control, I’m switching the animations to be based on the mouse angle. So, I’m still walking with keyboard or left stick, but now aiming and rotating the character with mouse or right stick.

I can post a clip tomorrow, if it’s still not clear.

ok, you could have 2 groups, 1 for changing the animation based on keypad and one for mouse aiming.

If mouse is down then do aiming, if [inverted] mouse is down then use the keys. Just put your events as sub-events so the mouse is only checked once and it ignores everything if the state doesn’t match,

This isn’t proper code. This was just a quick way for me to test it.

That’s more or less what I already have, so that’s not the issue :sweat_smile:

I’ll post a clip tomorrow, it will be easier to understand.

But thanks for the input so far!

1 Like

There you go, here’s the clip of my current controls:

I hope this helps.

Nice looking. Is there still a problem? Unless the player twists at the waist or the hands move independent of the body then I’m not sure what you want. You could aim with a crosshair cursor without changing the cat. The cat would follow the keys until the fire button was clicked. That might be nice. The cat would stop, turn and shoot and then continue to move.

If you have a plan, let us know. We’ll try to help.

Thanks, I am considering the solution you mentioned, in which the animation would only change when shooting, but was I was thinking of doing is when the animation is changing with the angle of the mouse, and I am walking in the opposite direction of the mouse angle I wanted to play the animation in reverse, so it looks like the character is walking backwards.

1 Like

It would be tough to walk in one direction while aiming in another. Unless the cat twisted at the waist or just turned its head or arms. You can play animations backwards by using a negative number for the speed scale.

image

Maybe the cat needs to draw the weapon first. It walks around until it draws its weapon then it looks at the cursor. You could reduce its max speed while the weapon is drawn. IDK, I’m just saying what comes to my mind. I’m trying to imagine different scenarios.

Thanks for the tips, I’ll try out some of the things you suggested and see if it’s working :smile:

1 Like