0 Favourites

How do I Limit rotation of a sprite

  • Hi there i been searching for weeks on this forum for this specific thing but i didnt have much luck i have tried everything that i could find on here and nothing worked,

    -I have an Arch like object with "set angle toward (mouse.x,mouse.y) on every tick.

    -and the arch set position to player image point 2 on every tick

    I need this this arch to stop rotating and remain fixed if the mouse causes the angle to be above say 260 or below 45.

    Also it will need need to work when the arch faces the other direction

    I just dont want it to shoot more or less strait up and down so it look more natural with the player when playing shoot animation

    thanks in advance

  • Maybe the clamp expression is what you are looking for?

    https://www.scirra.com/manual/126/system-expressions

    [quote:2vzjr6vg]clamp(x, lower, upper)

    Return lower if x is less than lower, upper if x is greater than upper, else return x.

  • Maybe the clamp expression is what you are looking for?

    https://www.scirra.com/manual/126/system-expressions

    [quote:2985ks98]clamp(x, lower, upper)

    Return lower if x is less than lower, upper if x is greater than upper, else return x.

    thank you oosyrag for poingting me that i think it looks like the right thing but i have no idea in how to implement it so i can test it, could you give me an example so i can follow it? im new to this and i have no programing experience thanks a lot

  • Sorry I don't have C2 on this computer, but it will look like this:

    Every Tick  |  ArchObject - Set angle to clamp(angle(ArchObject.X, ArchObject.Y, Mouse.X, Mouse.Y),45,260)[/code:tjtmsoad]
  • Sorry I don't have C2 on this computer, but it will look like this:

    Every Tick  |  ArchObject - Set angle to clamp(angle(ArchObject.X, ArchObject.Y, Mouse.X, Mouse.Y),45,260)[/code:366jra4u]
    

    wooow thats what i was looking for, i been going crazy with this thing, thanks huge thanks oosyrag

    the only problem i have now is doesnt mirroor to the left like before, the player looks to the left but the arch keeps looking to the right, do i have to ad any extra code to do the same for when is facing the left side? i will carry on trying lets see if i can fix it, thanks for your time bro

  • I manage to fix the mirroring but another problem now comes up when is mirrored at the left donsnt rotate smothly like when is at the right i cant figure out whats wrong

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

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Ah this one is a little tricky, because using angle() on the other side will jump from 180 to -180, instead of giving you 360 degrees.

    First thing, don't mirror the arch sprite, that will make things even more strange. For your condition, just check if the player is mirrored or not.

    If not mirrored - clamp(angle(arch.X, arch.Y, Mouse.X, Mouse.Y),-25,25)

    If mirrored - clamp(angle(mouse.X, mouse.Y, arch.X, arch.y)+180,155,205)

  • Ah this one is a little tricky, because using angle() on the other side will jump from 180 to -180, instead of giving you 360 degrees.

    First thing, don't mirror the arch sprite, that will make things even more strange. For your condition, just check if the player is mirrored or not.

    If not mirrored - clamp(angle(arch.X, arch.Y, Mouse.X, Mouse.Y),-25,25)

    If mirrored - clamp(angle(mouse.X, mouse.Y, arch.X, arch.y)+180,155,205)

    hoo yeaah is working perfect now :D :D thanks a lot for all your help oosyrag you saved me from loosing more hours, weeks just to fix this one thing jeje

    do you mind if i ask you one last question, how do you learn this things? i mean if im stack like on this examples and i was totally lost as i didnt know were to look or the mathematical part, but you knew all this things were do you learned? do i have to learn any specific programming language or something else? what do you reconmend? thanks a lot bro, sorry for so many questions, take care

  • Well I didn't really know off the top of my head, I had to experiment a little for the second answer. It is mostly trial and error, and some basic math. So... school!

    If you ever run into any programming problem, the best thing is to use debug mode to clearly see what the code is doing. Sometimes it doesn't work as you expect, as I found out with the angle() expression giving a negative value.

    So basically I put the expressions angle(arch.X, arch.Y, Mouse.X, Mouse.Y) and angle(mouse.X, mouse.Y, arch.X, arch.y) into variables to see what they were exactly when I moved the mouse around. Then it was a matter of changing the numbers into something I could use by adding 180.

    As for not mirroring, simpler is almost always better - easier to troubleshoot and fix. If you use mirror in this case, the up and down angles would be inverted. I'm sure you could still get it to work anyway, but it was just another layer of complexity to figure out.

  • Well I didn't really know off the top of my head, I had to experiment a little for the second answer. It is mostly trial and error, and some basic math. So... school!

    If you ever run into any programming problem, the best thing is to use debug mode to clearly see what the code is doing. Sometimes it doesn't work as you expect, as I found out with the angle() expression giving a negative value.

    So basically I put the expressions angle(arch.X, arch.Y, Mouse.X, Mouse.Y) and angle(mouse.X, mouse.Y, arch.X, arch.y) into variables to see what they were exactly when I moved the mouse around. Then it was a matter of changing the numbers into something I could use by adding 180.

    As for not mirroring, simpler is almost always better - easier to troubleshoot and fix. If you use mirror in this case, the up and down angles would be inverted. I'm sure you could still get it to work anyway, but it was just another layer of complexity to figure out.

    really cool staff i didnt know i can use the debug to find out whats causing the problem, that is something i will keep in mind from now on, i will have to experiment more with that to get use to it. the reason why i was asking is

    becouse i see many times to use something with "expressions" is like we have to know some math and programing skills other ways we get stack example: clamp(angle(ArchObject.X, ArchObject.Y, Mouse.X, Mouse.Y),45,260) i would have never know how to figure out by my self the symbols ( () ) math etc.... thats why i was asking to see if i can learn something extra like programing etc.... to improve my experience with construct 2

    and dont have to came back every time asking for help

    just trying to do anything that i can to learn in the right way

    huge thanks for all your explanations, an for your time, i learned many good things take care

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
Sprite Font Generator - v3
368 112,399
RetroDaddy's avatar
RetroDaddy
Unread hot topic
86 28,726
St4rDu57's avatar
St4rDu57
Unread hot topic
99 10,159
karshinkoff's avatar
karshinkoff