mouse click movement

Get help using Construct 2

Post » Mon Sep 26, 2011 1:45 pm

[QUOTE=Wastrel] @TheLure: the link to your capx isn't working. Is it in the public folder?

@Ashley: Thanks for the hint, i got that mostly working. Unfortunately, the sprite keeps creeping past the mouse click point.

Sorry Havok, I'm not trying to hijack your post.[/QUOTE]

No problem at all!

@ The Lure. Thanks a bunch... thats another way of working it but still is a little off (ALMOST there though). The arrow keeps on moving (like it has inertia ) I'll play a bit with this as well .

@Ashley. It's probably niche and minor... but I certainly think that Construct 2 can do with a Movement behavior specifically for this. Click to move to a point, with an option to constrain x or Y and then maybe a set speed as well would be great. Will this be at all doable in a future update?
It's obviously something a lot of people could use and is finding a bit difficult. it's also a movement feature that's used pretty often in certain types of games.


Havok2011-09-26 13:56:37
B
19
S
3
G
4
Posts: 79
Reputation: 3,711

Post » Mon Sep 26, 2011 4:40 pm

You can do it with the bullet movement and 2 events: example

I don't like making behaviors to replace such simple events. If we have many behaviors that do such simple things for you, I think Construct 2 will become patronising, and then people start expecting behaviors to do everything for you, which they're not designed for.

I've included that example in the next build's example directory too.Ashley2011-09-26 16:40:51
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Tue Sep 27, 2011 12:15 pm

Thanks Ashley!
That works perfectly!
B
19
S
3
G
4
Posts: 79
Reputation: 3,711

Post » Sun Apr 15, 2012 4:09 pm

So, I've recently come across a strange bug. First, I implemented the exact events of your click-move project. Then I added my own event that rotates the sprite according to the mouse position. However, when I do this, clicking exactly below the sprite causes it to move straight left or right for no reason.
Do you know any way I can alleviate this problem?
B
3
Posts: 4
Reputation: 283

Post » Sun Apr 15, 2012 4:21 pm

Oh silly me, I forgot the code:

Event: If Player Bullet Speed = 0
Action: Player Set Angle Toward Target.x Target.y
B
3
Posts: 4
Reputation: 283

Post » Mon Jul 02, 2012 11:51 pm

[QUOTE=TheLure] I used CustomMovement to create this effect.
I made object variables for the player target X and Y. When the mouse is clicked I set target XY to the mouse XY.
Then I just compare the players XY against his target XY and if they differ I turn the player sprite towards the target XY and give him some acceleration.
When players is near the target XY I stop the movement.

Example capx here

I guess you can use bullet behaviour also the same way.[/QUOTE]

For your example TheLure I would suggest adding one more action to your Mouse Click event "Set CustomMovement Overall Speed to 0"

This prevents the player sprite from circling the target when a second click is performed before the previous move has been completed.

Though I did find it quite fun to try and get the player to stop moving with more clicks before I implemented the speed cancel. Your example helped me a lot :)
B
6
S
3
G
1
Posts: 102
Reputation: 1,379

Post » Thu Jul 26, 2012 2:43 pm

[QUOTE=Ashley] You can do it with the bullet movement and 2 events: example

I don't like making behaviors to replace such simple events. If we have many behaviors that do such simple things for you, I think Construct 2 will become patronising, and then people start expecting behaviors to do everything for you, which they're not designed for.

I've included that example in the next build's example directory too.[/QUOTE]

Sorry to bump an old thread, but this seemed relevant to me right now. The behaviour i want was achieved via Kyatric's Automated movement.capx but with the 'set angle' turned off. This makes the sprite move to mouse location while not rotating the sprite (the way i want it). My goal is to basically play different animations depending on the angle the character moves at (that part i got covered). Doing it with bullet movent also rotates the animation though and i cant seem to find a solution that way.

Is there a way of doing this by way of your example, Ashley? I've tried turning off "Set Angle" off but this keeps the bullet movement to the original angle (as one would expect.
B
6
Posts: 30
Reputation: 1,260

Post » Thu Jul 26, 2012 2:48 pm

@silvereon:

When you turn off the "Set angle" property, you control the bullet with the "Set bullet angle of motion" action. To play different animations based on angle you need to use a condition like "System: Compare Two Values" and compare "Sprite.Bullet.AngleOfMotion" with whatever you had in mind.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Thu Jul 26, 2012 2:55 pm

Yeh i know how to play different animations based on angle of motion.

And adding action "Set Angle of motion" to value "mouse.X, mouse.Y" - i get an error "Syntax Error - expression seems to stop here" and it points in between the mouseX and mouseY.
B
6
Posts: 30
Reputation: 1,260

Post » Thu Jul 26, 2012 3:03 pm

@silvereon:
That action expects an angle and not a position, so you need to use the angle expression:

angle(YourSprite.X, YourSprite.Y, Mouse.X, Mouse.Y)Nimtrix2012-07-26 15:06:20
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 24 guests