How do I push opject to mouse position

0 favourites
  • 5 posts
From the Asset Store
Push the Box Puzzle Game likes Sokoban made with Illustrator
  • i have sprite spawn object i want to know how to make spawned object to move frome sprite to mouse croshere position i.x move from point a and stop on point b ( mouse crosehere )

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi ismailsawan... there are many ways you can do it, but there is the "easiest"

    If you want it to walk into the crosshair (cursor) you can use a Bullet Behavior, and constantly change its angle of motion to "angle(Sprite.x,Sprite.Y,Mouse.X,Mouse.Y)".

  • Thank You HenryPK,

    exactly i do that but i want the spawned object to stop on mouse cross hair i click on screen... the bullet behavior make spawned object move out the layout can you find way to do that

    great thanks for your help.

  • To move to cross hair on screen such as an RTS it is better to use the pathfinding behaviour, the object in question probably having 8-direction behaviour as well. When you click, mouse.x,mouse.y becomes the destination for the object to move to. On click, object find path to mouse.x, mouse.y.

  • Thank You HenryPK,

    exactly I do that but I want the spawned object to stop on mouse cross hair I click on screen... the bullet behaviour make spawned object move out the layout can you find a way to do that

    great thanks for your help.

    Oh, you can make it like this with 3 objects (The Mouse, the Sprite, and a "target" invisible(or not) object):

    On "Mouse" Click >>

    - Set "Target" position to (Mouse.X, Mouse.Y)

    When you click, it will bring the target to the mouse position.

    "Target" Is On Screen >>

    - "Sprite" set Bullet angle of motion to:" angle (Sprite.x,Sprite.y,Target.x,Target.y)

    If there's a target on screen, will move towards it

    Else (Target Is not on screen) >>

    - "Sprite" set Speed to 0

    Won't move if there is no target onscreen

    "Sprite" on collison with "Target" >>

    - "Target" set position to "-Target.Width,-Target.Height)"

    This will make the target go off screen when the Sprite reaches its destination.

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