How do I stop jittering when object reaches mouse?

0 favourites
  • 7 posts
From the Asset Store
Create your game with this complete pack of images and animations!
  • Hi! First time poster, so I apologize if my formatting is a bit off - been using Construct 3 for about 2 and a half months now; long story short, I'm making a vertical scroller/runner/shooter game for a client and after making it with 8-directional controls, he now wants the player to follow the mouse for directional control...

    I have accomplished that with a bullet behaviour and having the angle of motion calculated towards the mouse with every tick, however when the 'player' reaches the mouse it jitters. I tried to compare if the mouse was +- 50 pixels from the player and only set the angle of motion to the mouse if it is outside of that range.. I am assuming that's the issue anyways.

    [

    pseudo code: System > Compare mouse.x not equal player.x +- 50 AND System > Compare mouse.y not equal player.y +- 50 >> player bullet behaviour set angle of motion to angle(player.x,player.y,mouse.x,mouse,.y)]

    I have only actually been "coding" for maybe 3-4 months, too, so I may not be using the right terms and expressions as well.. or going about this in a really clunky way lol.

    One other tidbit, the player is a spriter object (using the plugin) pinned to a sprite because I had to use spriter for some animations and the sprite object for some collision detection and movement controls.

    Please let me know if there is any more information I can provide to help you help me xD

  • You can use distance() expression:

    If distance(Player.x, Player.y, Mouse.x, Mouse.y)<50, then set angle of motion.

    However, if mouse cursor is not moving, the player will keep moving back and force within 50 px of it.

  • What dop said, but you can also try disabling the bullet behavior when the sprite is less than x distance from mouse, and enabling it when more.

    If your player object is moving very quickly, you can use the stepping property and events to prevent overshooting your mouse position.

  • This really helped, thank you so much dop2000 and oosyrag; the jittering has stopped, I ended up doing two conditions [pseudo code: System - distance(player,mouse) > 50 and < 50 ... with the > I have player enable bullet and set angle of motion to the mouse, and with the < I have player disable the bullet behaviour] ... but it feels really clunky still.. I am now having an issue with the speed seeming to increase over time and my collisions are wonky (sorry about all the technical jargon xD) - but that could be due to a "jump" command I have configured which is extremely clunky, at best.

    Should I be using dt to calculate speed with the bullet behaviour in my event sheet or would setting the speed to 20 using the behaviours section in the properties panel suffice?

  • my collisions are wonky"

    The issue with collisions actually seems to be when the mouse is within the player's bounding box and/or within the condition where the player disables the bullet behaviour.

    I do have the bullet set to "bounce off of solid objects", is that what's actually controlling my player's 'collisions' when the bullet behaviour is enabled?

    Edit: instead of disabling and enabling I set the speed to 0 when it would have been disabled and re-set it to 25 to enable.. collisions work perfectly now, but it seems to still be having this "over time issue though" where its SUPER slow at first and gets faster and faster...

  • Dt should not be used when setting behavior properties, as behaviors are already made to be framerate independent.

    I do not understand your second question.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you oosyrag , I don't fully understand how to use 'DT' yet lol. I ended up disabling a lot of my clunky 'code' and figuring out where the issues were hiding after inserting the suggestions you made, above - my player now follows the mouse and stops when reaching it, no jittering and collisions are working perfectly!

    Thank you again for all of your help :D

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