So im creating this gun game and i want the character to look at the mouse, because it would look like they are turning to shoot. But i dont want my character to move, just stay still in the middle of the screen. I also have all the animations for the character looking up, down, left, right, and 4 more directions that are in-between those main directions. Anyways, I’m struggling to have the animations for looking those directions activate by the position of the mouse on the screen, and everytime i try to figure it out the coding gets super hard. If you wanna check out the game its right here: STAY. ALIVE. - Flowlab Game Creator
There’s a way to do it, where you take the cursors X and Y position and use filters to determine if it’s in one corner or another. It’s kind of difficult to explain, but if you send a link to you game, I’ll check it out and make an example for you when I get out of my classes.
I’ve done this myself for my top down shooter, but mine is 8 directional, not 4, so it’s a bit more complicated, but a 4 way direction isn’t too bad.
I am also using an 8 directional looking system
I will get a system, are you using 8 animations then?
yes i am thank you!!
UPDATE: I DONT NEED THIS ANYMORE, ive decided to completely revamp the moving system. i would still like a solution though
Ok! Here is the code anyway!
It converts the rotation to an integer.
Like;
- 0° → 1
- 45° → 2
- 90° → 3
And so on.
{"data":{"behavior":{"v":"2","nodes":[{"inputCount":3,"outputCount":0,"name":"Sand Gravity","behaviorType":"logic.NodeGroup","x":-630,"y":304,"group":"","id":"6fd67a821eb8e145","notes":"Made for FlowlabRunnerPlayer301","n_o":1,"isMenuItem":false},{"inputCount":0,"outputCount":1,"name":"Bundle Input","behaviorType":"logic.NodeGroupInput","x":-90,"y":128,"group":"6fd67a821eb8e145","id":"6fd67a824c3f8343","portId":"6fd67a821eb8e145i0","tag":"On","dataType":2},{"inputCount":0,"outputCount":1,"name":"Bundle Input","behaviorType":"logic.NodeGroupInput","x":-90,"y":48,"group":"6fd67a821eb8e145","id":"6fd67a82970c7e45","portId":"6fd67a821eb8e145i1","tag":"Off","dataType":2},{"inputCount":0,"outputCount":1,"name":"Bundle Input","behaviorType":"logic.NodeGroupInput","x":-90,"y":208,"group":"6fd67a821eb8e145","id":"6fd67a823d230043","portId":"6fd67a821eb8e145i2","tag":"Force","dataType":2},{"expression":"-A","default0":0,"default1":0,"default2":0,"default3":0,"default4":0,"default5":0,"params":2,"version":2,"tag":"","inputCount":3,"outputCount":1,"name":"Expression","behaviorType":"logic.logic.Expression","x":90,"y":160,"group":"6fd67a821eb8e145","id":"6fd67a838618f644"},{"inputCount":0,"outputCount":1,"name":"Once","behaviorType":"logic.triggers.Once","x":-90,"y":-32,"group":"6fd67a821eb8e145","id":"6fd67a83d78e5a42","resetOnLevelStart":false},{"inputCount":1,"outputCount":1,"name":"Extractor","behaviorType":"logic.properties.Extractor","x":90,"y":-48,"group":"6fd67a821eb8e145","id":"6fd67a83f761da49","targetId":0,"prop":"x","version":2},{"delay":0,"count":0,"version":2,"inputCount":3,"outputCount":1,"name":"Timer","behaviorType":"logic.triggers.Timer","x":90,"y":48,"group":"6fd67a821eb8e145","id":"6fd67a8373f21244"},{"inputCount":3,"outputCount":1,"name":"Number","behaviorType":"logic.logic.Value","x":270,"y":0,"group":"6fd67a821eb8e145","id":"6fd67a83716ab24c","startVal":0,"roundMode":1},{"inputCount":4,"outputCount":2,"name":"Position","behaviorType":"logic.properties.Position","x":450,"y":16,"group":"6fd67a821eb8e145","id":"6fd67a845c88ba4f","pixelUnits":true,"resetVelocity":false},{"inputCount":3,"outputCount":3,"name":"Push Motor","behaviorType":"logic.components.Motor","x":450,"y":160,"group":"6fd67a821eb8e145","id":"6fd67a8498194f47"},{"inputCount":3,"outputCount":1,"name":"Number","behaviorType":"logic.logic.Value","x":270,"y":160,"group":"6fd67a821eb8e145","id":"6fd67a843db40a4d","startVal":-60,"tag":"","roundMode":1},{"inputCount":2,"outputCount":0,"name":"AngleToInteger","behaviorType":"logic.NodeGroup","x":-630,"y":432,"group":"","id":"d5e4a1330bc91742","notes":"Made for JSoft\n","isMenuItem":false},{"inputCount":0,"outputCount":1,"name":"Bundle Input","behaviorType":"logic.NodeGroupInput","x":-90,"y":-32,"group":"d5e4a1330bc91742","id":"d5e4aac54923c540","portId":"d5e4a1330bc91742i0","tag":"X","dataType":2},{"inputCount":0,"outputCount":1,"name":"Bundle Input","behaviorType":"logic.NodeGroupInput","x":-90,"y":80,"group":"d5e4a1330bc91742","id":"d5e4c08abfbd2145","portId":"d5e4a1330bc91742i1","tag":"Y","dataType":2},{"expression":"Math.abs(Math.floor(A/45))+1","default0":0,"default1":0,"default2":0,"default3":0,"default4":0,"default5":0,"params":1,"version":2,"tag":"Convert","inputCount":2,"outputCount":1,"name":"Expression","behaviorType":"logic.logic.Expression","x":270,"y":16,"group":"d5e4a1330bc91742","id":"d5e4ddef96d54542"},{"inputCount":2,"outputCount":1,"name":"PointAt","behaviorType":"logic.components.PointAt","x":90,"y":16,"group":"d5e4a1330bc91742","id":"d5e5786aa7424648","skipRot":false},{"inputCount":2,"outputCount":8,"name":"Router","behaviorType":"logic.logic.Router","x":450,"y":-16,"group":"d5e4a1330bc91742","id":"d5e825ac43ce4c48","loop":true,"routes":8,"mode":0},{"inputCount":1,"outputCount":2,"name":"MouseMove","behaviorType":"logic.triggers.MouseMove","x":-810,"y":432,"group":"","id":"d5e5a742c1aa4947","gameCoords":false}],"links":[{"input_id":"d5e4a1330bc91742i0","output_id":"d5e5a742c1aa4947o0"},{"input_id":"d5e4a1330bc91742i1","output_id":"d5e5a742c1aa4947o1"},{"input_id":"d5e4a1330bc91742i0","output_id":"d5e5a742c1aa4947o0"},{"input_id":"d5e4a1330bc91742i1","output_id":"d5e5a742c1aa4947o1"},{"input_id":"6fd67a8373f21244i1","output_id":"6fd67a824c3f8343o0"},{"input_id":"6fd67a8373f21244i0","output_id":"6fd67a82970c7e45o0"},{"input_id":"6fd67a838618f644i0","output_id":"6fd67a823d230043o0"},{"input_id":"6fd67a838618f644i2","output_id":"6fd67a823d230043o0"},{"input_id":"6fd67a843db40a4di0","output_id":"6fd67a838618f644o0"},{"input_id":"6fd67a843db40a4di1","output_id":"6fd67a838618f644o0"},{"input_id":"6fd67a83f761da49i0","output_id":"6fd67a83d78e5a42o0"},{"input_id":"6fd67a8373f21244i0","output_id":"6fd67a83d78e5a42o0"},{"input_id":"6fd67a83716ab24ci0","output_id":"6fd67a83f761da49o0"},{"input_id":"6fd67a83716ab24ci1","output_id":"6fd67a8373f21244o0"},{"input_id":"6fd67a843db40a4di1","output_id":"6fd67a8373f21244o0"},{"input_id":"6fd67a845c88ba4fi0","output_id":"6fd67a83716ab24co0"},{"input_id":"6fd67a8498194f47i1","output_id":"6fd67a843db40a4do0"},{"input_id":"d5e5786aa7424648i0","output_id":"d5e4aac54923c540o0"},{"input_id":"d5e5786aa7424648i1","output_id":"d5e4c08abfbd2145o0"},{"input_id":"d5e825ac43ce4c48i0","output_id":"d5e4ddef96d54542o0"},{"input_id":"d5e825ac43ce4c48i1","output_id":"d5e4ddef96d54542o0"},{"input_id":"d5e4ddef96d54542i0","output_id":"d5e5786aa7424648o0"},{"input_id":"d5e4ddef96d54542i1","output_id":"d5e5786aa7424648o0"}]}}}
Simply just an expression.
Math.abs(Math.round(A/45))+1
you could have just used the mouse and set it into the point at behavior. if your game is top-down anyway