[SOLVED] Move Sprite at angle following mouse's movement

Get help using Construct 2

Post » Sun Oct 30, 2016 9:53 pm

Hey everybody, been stuck with this for a while.

Following scenario:
I'm building a (very) simple pool game. Currently, I'm setting up the basic control of the queue.
Basically, what I'm trying to do is this:
  • When the mouse button is pressed, the queue's angle gets locked (no problemo)
  • the queue gets moved on its current angle according to the distance the mouse gets moved while the mouse button is pressed (here is the issue)
  • the queue should just be movable in one direction

I figured, I have to do some sinus and cosinus callculations to be able to perform this for every possible queue angle.
I worked out some solutions, experimented a bit with lerp, but in the end, I couldn't combine both x and y coordinates. One on its own (obviously) wouldn't be much of a problem.

If there would be a way to combine both X and Y distance of the Mouse, then I could use the "move forward" action for the queue..

Did I explain well what I'm up to?
If not, I'm happy to explain if there are questions.
As always, anyy help is aprecciated.
Thank you.
Last edited by randomly on Mon Oct 31, 2016 3:53 pm, edited 1 time in total.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sun Oct 30, 2016 10:12 pm

You just set a co-ord into a variable for initial touchxy. Assuming you already have the angle for the cue set to i.e. 0, I would then move the cue at angle 0 every tick (position + the distance between current touchxy and initial touchxy. ) So if you're holding down and have dragged 50 pixels then the cue moves at angle 0 for 50 pixels, the distance between initial touch and current touch. Also it's a CUE, if you're making a pool game :P
B
47
S
17
G
82
Posts: 2,230
Reputation: 48,607

Post » Sun Oct 30, 2016 10:45 pm

Good to know, thought it was spelled differently :D

Your solution seems pretty obvious.
Though how should I calculate the variable of the distance containing both X and Y coordinates?

Maybe, I wasn't clear enough:

I don't want the cue to follow the mouse. Assuming the cue is at angle 0 for example, in that case I would want it to just follow the x movement of the mouse.
If the cue was at 90 degrees, just the Y movement.
And at 45 degrees for example, a combination of X and Y.
This combination is what bugs me.

Since I'm no native English speaker, my intentions may not seem too obvious. :D
Maybe this is easier to understand:

When the mouse button is down, I want the cue to follow the mouse, but at the same time, the cue should be restricted to only move on a line having the current cue's angle.
(As if it had the drag and drop behaviour and there were walls parallel to the cue)


Could also be possible that I misunderstood your solution.
I uploaded my .capx here: https://www.dropbox.com/s/aemopym3697i7 ... .capx?dl=1
Maybe you can just download it, edit it and upload the working result so that I can understand your solution. :)
(all the disabled events are what I tried to geet it to work)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sun Oct 30, 2016 11:18 pm

Well my method would work if the angle was predefined and wasn't open to change. Sounds like you want it to update the cue's angle constantly based on the angle that themouse is moving at so I guess yeah you'll have to do some maths here and calculate some angles. Good luck! xD I'm sure someone could come up with a solution tbh, maybe I could after some sleep.
B
47
S
17
G
82
Posts: 2,230
Reputation: 48,607

Post » Mon Oct 31, 2016 12:30 am

Just to clarify this: as soon as the dragging starts, the angle of the cue stays constant.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Mon Oct 31, 2016 10:36 am

something like this ?

angleLock.capx

Image
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Mon Oct 31, 2016 3:52 pm

@Korbaach

Are you Jesus?

That is brilliant and exactly what I need.
Obviously, I didn't see that I need to divide the distance by 2...(any easy-to-understand explanation for that to make a math noob understand what he is implementing in his project?)
And I forgot about the "distance" expression. :roll:

Thank you very much, this thread is SOLVED!

(Also, @plinkie thank you very much for your posts. :) )
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Mon Oct 31, 2016 5:42 pm

Ah very nice, I made an attempt but I couldn't do it that well, I'm more of a debugger than a maths wizard.
B
47
S
17
G
82
Posts: 2,230
Reputation: 48,607

Post » Mon Oct 31, 2016 8:59 pm

@plinkie

Still appreciate your efforts, thank you. :)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Mon Oct 31, 2016 10:02 pm

korbaach wrote:something like this ?

angleLock.capx

Image


Wow. I think you may have just helped me solve a problem for one of my own games builds. Thanks...?!?!?!
B
223
S
125
G
8
Posts: 146
Reputation: 22,243


Return to How do I....?

Who is online

Users browsing this forum: Artcadev and 18 guests