Sprite move away from mouse drag.

0 favourites
  • 5 posts
From the Asset Store
Create your game with this complete pack of images and animations!
  • Hello and thanks for your interest. I'm trying to set it up so when I left click and drag the mouse a sprite will move away from the mouse the same distance and angle the mouse is dragged. I have tried to use the move at angle action paired with the Mouse.Absolute X-Y features but cant get it to work. Also it's important that the sprite doesn't rotate. I'm completely stumped. Any of you upper echelon programmers got any ideas?     <img src="smileys/smiley4.gif" border="0" align="middle" />

  • If I get it right, you mean:

    If I drag the mouse up, the sprite goes down

    If I drag left, the sprite goes right

    Etc..

    I would say :

    On any left Click :

    Set a variable named OriginalmouseX to Mouse.X; Set a variable named OriginalmouseY to Mouse.Y

    Set a variable named OriginalSpriteX to Sprite.X; Set a variable named OriginalSpriteY to Sprite.Y

    left click is down :

    Set Sprite position to:

    X : OriginalSpriteX - (-OriginalmouseX+Mouse.X)

    Y : OriginalSpriteY - (-OriginalmouseY+Mouse.Y)

    I think this will work (if the sprite go to the same direction as the mouse, just change the - to a +, sometimes I make error with signs)

  • Hey Aphrodite thanks for the help this is exactly what I asked for. After implementing the solution I realized the sprite was moving a bit to slow so I made a small adjustment.

    OriginalSpriteX - (-OriginalmouseX+Mouse.X)*6.5

    It still needs some fine-tuning but I'm gonna keeping playing with it. There is one issue I ran into when testing. I noticed that if I'm using full screen mode and decrease the window size the sprite seems like it's moving faster. It's really not. It just has less space to cover before it's out of the canvas. Do you know of any way to adjust the distance the sprite will move based on the size of the canvas?

  • Hey Aphrodite thanks for the help this is exactly what I asked for. After implementing the solution I realized the sprite was moving a bit to slow so I made a small adjustment.

    OriginalSpriteX - (-OriginalmouseX+Mouse.X)*6.5

    It still needs some fine-tuning but I'm gonna keeping playing with it. There is one issue I ran into when testing. I noticed that if I'm using full screen mode and decrease the window size the sprite seems like it's moving faster. It's really not. It just has less space to cover before it's out of the canvas. Do you know of any way to adjust the distance the sprite will move based on the size of the canvas?    

    Kahless

    Maybe the WindowWidth and WindowHeight expression can help you, they adjust to the size of the window displaying the game.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Aphrodite

    Awesome. Once again exactly what I was looking for. Thanks for the help.

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