How do I set angle toward mouse but stop within certain #°

0 favourites
  • 13 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • I have the angle working, but I have no idea how I can stop the object "rotating" towards the mouse. My character has a gun and it rotates towards the mouse and the gun flips and the character gets mirrored when the mouse is either side of the character.

    The thing is, I do not want the gun to keep rotating past a certain degree, as at the moment it will clip inside the player. I want to try and have it so it only rotates along an arc of about 80° .

    Does anyone know how to do this?

  • rotate towards min(the_angle, max_angle)

    min() = take the lowest of both values

    the_angle = angle towards mouse

    max_angle = the maximum that you allow it to rotate

  • I can't seem to find the right event to use within the angle section. I've tried different things but I'm not 100% and nothing has worked. Could you put a quick example together please?

  • I always forget that angles increase/decrease different around zero point.

    I also wanted it to work flawless when the dude jumps.

    So i used a little trick.

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

    Hope it brings you somewhere.

  • I can't seem to find the right event to use within the angle section. I've tried different things but I'm not 100% and nothing has worked. Could you put a quick example together please?

    I looked at your CAPX but because you are using Pin To and set angle and position that interferes with trying to read the angle and keep it from going past 270 and below 40 degrees.

    I tried several things but that Pin keeps over riding it and locking the head in weird positions.

    I think you need a rotation joint and physics to accomplish what you are trying to do or use a blank sprite as a block to keep head from over rotating.

  • Thanks 99Instances2Go, I don't actually understand what all the maths mean that gets the gun to rotate, such as "clamp" and "sin". I guess I could copy it to my game, but I would not really ever understand how it works.

  • clamp(x, lower, upper)

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

    As long as X is between 'lower' and 'upper', the result = x

    If x is lower then 'lower', the result is 'lower'

    If X is higher then 'upper', the result is 'upper'.

    Say you want to constrain the Y position of a sprite between 100 pixels and 500 pixels.

    Set y of the sprite to clamp(sprite.y , 100 , 500)

    sin(angle).

    Say you have a bullet flying at an angle. If the bullet travels 1 unit (in the direction of the angle) then it travelled a distance of sin(angle) on the Y and cos(angle) on the X.

    Easier said: To move a bullet at a angle of 60 degrees, you move it cos(60) in the X and sin(60) on the Y.

    And that is all there is to say about cos(angle) and sin(angle), except maybe that is scalable.

    If you move a bullet at x= cos(60) * 50 & y=sin(60) * 50, it still moves at an angle of 60 degrees, just 50 times faster.

  • I have the angle working, but I have no idea how I can stop the object "rotating" towards the mouse. My character has a gun and it rotates towards the mouse and the gun flips and the character gets mirrored when the mouse is either side of the character.

    The thing is, I do not want the gun to keep rotating past a certain degree, as at the moment it will clip inside the player. I want to try and have it so it only rotates along an arc of about 80° .

    Does anyone know how to do this?

    Here add this line to your Every Tick event:

    That prevents the head from rotating beyond 270 and 90.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 99Instances2Go Thanks for explaining!

    lamar I did not include any example of my game, so I'm not sure if you have mixed up 99Instances2Go example to be my work?

  • 99Instances2Go Thanks for explaining!

    lamar I did not include any example of my game, so I'm not sure if you have mixed up 99Instances2Go example to be my work?

    No that is not 99's capx which I never download.

    Are you saying this robot with the head that kept rotating was not yours because I am sure you posted that link?

    Maybe you just like to play games in the forum.

  • lamar Its not mine, I don't have a head sprite and my character is not a robot. Can you link to the post, kind of interested in what it is now.

  • You "I have the angle working, but I have no idea how I can stop the object "rotating" towards the mouse. My character has a gun and it rotates towards the mouse and the gun flips and the character gets mirrored when the mouse is either side of the character."

    The thing is, I do not want the gun to keep rotating past a certain degree, as at the moment it will clip inside the player. I want to try and have it so it only rotates along an arc of about 80° .

    Does anyone know how to do this?"

    Link that was on your post:

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

    Picture of the character:

    Now if that isn't yours who's is it and it fits your OP perfectly and I wasn't following any one else's post that had that problem?

    Never mind- It was BobbyNeal and your post was asking the same question describing the same character and aiming probs.

    Sure you aren't using two accounts?

    Anyway, that is the solution for that aiming problem.

  • lamar I'm not that guy xD I'm going to have to check it out now.

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