Sprite move away from mouse drag.

Get help using Construct 2

Post » Mon Sep 16, 2013 10:11 pm

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?     
B
5
Posts: 14
Reputation: 253

Post » Mon Sep 16, 2013 10:27 pm

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)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Tue Sep 17, 2013 12:04 am

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?    
B
5
Posts: 14
Reputation: 253

Post » Tue Sep 17, 2013 12:46 am

[QUOTE=Kahless] 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?    [/QUOTE]

@Kahless

Maybe the WindowWidth and WindowHeight expression can help you, they adjust to the size of the window displaying the game.Aphrodite2013-09-17 00:47:22
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Tue Sep 17, 2013 1:23 am

@Aphrodite

Awesome. Once again exactly what I was looking for. Thanks for the help.
B
5
Posts: 14
Reputation: 253


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound, wizdigitech, Zamargo and 15 guests