How do I create a variable offset from the mouse?

0 favourites
  • 3 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • What I am trying to do is create an object that will sort of follow the mouse, but it coordinates are always in multiples of 16. Right now, the origin of the object is in the top left corner at (0, 0). What I want to happen is when you move the mouse to lets say (17, 18), the object will go to (16, 16), same with if i had a coordinate like (22, 19). But then if I move the mouse to 33, 35, the object goes to (32, 32). Nothing I have tried seems to work. My latest attempt is posted here. What it does now is when MouseGridX and MouseGridY are both a multiple of 16, the object locks in place.

  • Sprite set position to X=round(Mouse.X/16)*16, Y=round(Mouse.Y/16)*16

    If you have a tilemap and you need that sprite to follow tiles, you can use Tilemap.SnapX, Tilemap.SnapY, Tilemap.PositionToTileX and Tilemap.PositionToTileY expressions.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sprite set position to X=round(Mouse.X/16)*16, Y=round(Mouse.Y/16)*16

    If you have a tilemap and you need that sprite to follow tiles, you can use Tilemap.SnapX, Tilemap.SnapY, Tilemap.PositionToTileX and Tilemap.PositionToTileY expressions.

    That worked! Thank you so much!

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