[SOL]How do i move an object until reach the mouse position?

  • Hello!

    It's my first post here, sorry for anything.

    I want to click in some screen location and make the player move until reach that mouse location that i clicked.

    How can i do it?

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Give the player pathfinding, have an event for when the mouse is clicked to set the pathfinding to that point, then when the path is found make the player walk the path.

  • Give the player pathfinding, have an event for when the mouse is clicked to set the pathfinding to that point, then when the path is found make the player walk the path.

    But the pathfinding will ignore the wall. I didn't say about these detail, sorry.

    The player must receive an impulse and he will only stop if reach the mouse position or some wall.

    He need to go in a line.

  • This would do it. Note the tab means it's a sub-event.

    repeat distance(sprite.x,sprite.y,mouse.x,mouse.y) times
    --- sprite: move 1 pixel at angle(sprite.x,sprite.y,mouse.x,mouse.y) degrees
    	sprite: overlaps wall
    	--- stop loop
    	--- sprite: move -1 pixel at angle(sprite.x,sprite.y,mouse.x,mouse.y) degrees[/code:1l6cma2z]
    
    Edit:
    Opps, that will do it instantly
    
    You can make it move gradually, say 100 pixels per second, with the following:
    [code:1l6cma2z]repeat min(distance(sprite.x,sprite.y,mouse.x,mouse.y), 100*dt) times
    --- sprite: move 1 pixel at angle(sprite.x,sprite.y,mouse.x,mouse.y) degrees
    	sprite: overlaps wall
    	--- stop loop
    	--- sprite: move -1 pixel at angle(sprite.x,sprite.y,mouse.x,mouse.y) degrees[/code:1l6cma2z]
  • This would do it. Note the tab means it's a sub-event.

    repeat distance(sprite.x,sprite.y,mouse.x,mouse.y) times
    --- sprite: move 1 pixel at angle(sprite.x,sprite.y,mouse.x,mouse.y) degrees
    	sprite: overlaps wall
    	--- stop loop
    	--- sprite: move -1 pixel at angle(sprite.x,sprite.y,mouse.x,mouse.y) degrees[/code:39zjoyl7]
    
    Edit:
    Opps, that will do it instantly
    
    You can make it move gradually, say 100 pixels per second, with the following:
    [code:39zjoyl7]repeat min(distance(sprite.x,sprite.y,mouse.x,mouse.y), 100*dt) times
    --- sprite: move 1 pixel at angle(sprite.x,sprite.y,mouse.x,mouse.y) degrees
    	sprite: overlaps wall
    	--- stop loop
    	--- sprite: move -1 pixel at angle(sprite.x,sprite.y,mouse.x,mouse.y) degrees[/code:39zjoyl7]
    

    Thanks!

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