How do I get rid of the jump to random angle while rotating?

0 favourites
  • 3 posts
From the Asset Store
*** 2D top down animated rotating trap game asset ***
  • Hi

    I’m working on a prototype and trying to rotate the screen with the mouse, but now I’ve hit the brick wall.

    Player is supposed to be facing up all the time and screen (layout) is supposed to rotate clockwise when right mouse button is down and mouse is moved to the right, and counter clockwise when mouse is moved to the left. With keyboard (A or D pressed without right clicking) it’s working perfectly, but with mouse when you right click, the screen jumps to random angle. After this jump it’s working like it supposed to be. I have also tried to get rid of the jump by using this Mouse Lock plugin which gives you more mouse functions, and I was able to prevent it to jump when right clicking, but as soon as you moved the mouse, screen jump rotated again to random angle.

    Does anyone have any clue how to solve this and prevent screen/layout to jump rotate to random angle?

    My prototype file: Prototype2.capx

  • Hi there,

    the angle is not random, you are trying to assign a linear value to an angle. to see what I mean, put a text object next to your player

    Now in a tick event, set the text value to mouse.absoluteX, then move your mouse left and right (on the X axis)...

    that value is the value you are trying to feed into your layout angle, as you can see, moving your mouse to X position 3600px for instance will spin your layout around 10times. (And land up at "a random angle") This is the only reason why you are seeing this "jump", because the update only happens when you right click.

    (Try take the first action in Event 25 (Set layout_angle to Mouse.AbsoluteX) and move it into a system tick event and move your mouse left and right to see what I mean.

    Now saying that, I think the mouse lock plugin you mentioned should be able to give you a pixel difference between a zero point (wherever the mouse is when you pressed the right button) and the current position of the mouse once moved. My guess is that you should be able to use this difference to emulate the keyboard rotations (Add rotSpeed*dt to layout_angle)

    For what it's worth, I don't think this is the best implementation of rotating the world around the character, as you'd probably not be able to use a UI with this "effect" (it'll be spinning around with the Layout... good luck with reading your score... (or you'd land up creating more overhead for your processor by trying to set UI elements the same way you set the player on Every tick to rotate "up")

    Also the player becomes rather glitchy when holding down the right mouse button, running forward, and trying to rotate with the keyboard. ( A good indication that this isn't the right way of implementing your idea...

    There is a saying... "There are many ways to skin a cat" I think it applies here... Try a different approach to doing the same thing. (Like emulating the keyboard movements (And I'm not saying that it is the right way, in fact it's probably not, but it might be ), or maybe rotating other objects, or layers, or something... just try some creative thinking around your problem.)

    Let me know if this points you out of the wrong direction...

    PS. Just try and emulate what you are already doing with the keyboard A + D keys onto your mouse as a start, or as an alternate solution, check out performance etc... who knows, there is probably a better way than that too

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hello and thanks for the reply.

    Well yes I know that it is not really a random angle, but it feels like it is to a player. I don't understand the logic behind it perfectly but it will set the angle depending on where the cursor is at the X axis when the right button is clicked and that causes the “jump”, maybe the logic goes just like you said.

    After I posted that question I started playing with ui/hud and already realized that if I'm using layout angle for rotation, it will rotate the hud around as well. So I changed rotation to only take account layers 0 and 1, and now hud will stay where it should be.

    Player is supposed to strafe when right button is down and A or D is pressed, and rotate when right button is not down. So now strafing is quick and easy to use and you don't need to set different keys for it. This maybe explains the “glitchy” feeling.

    Currently I don't know how to implement those add and subtract commands with mouse correctly and that is why I was using layer/layout rotation. But if that what you suggested doing with the mouse lock is possible it might work, I'll try it out.

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