mouse click movement

Get help using Construct 2

Post » Thu Sep 15, 2011 9:11 pm

I'm trying to figure out what the best way is to let my player sprite move to where the Mouse is.

What would be really helpful is a behaviour that will allow me to set the player movement speed as well as letting him move to the current mouse.x and mouse.y I know there must be a way, I am just too noob to figure it out it seems. If I set it to current mouse X or Y with position it jumps there instead of moving towards it. I have coded something klike this before saying:
X = X++1 until the mouse is let go but how do I set it in C2?
I suppose I could use 'On Every Tick' but that seems kinda wasteful?

How possible will it be to also restrict the Y movement?
So lets say I click on a co ordinate the player will move towards the x co-ordinate (left and right only) and not move up or down at all?

There must be a way but I would maybe think that it's such a common control interface in multiple games that it will have a behaviour dedicated to this kind of movement. Havok2011-09-15 21:18:08
B
19
S
3
G
4
Posts: 79
Reputation: 3,711

Post » Thu Sep 15, 2011 9:57 pm

Have a look at this, it might be useful to what you're tying to do, it's a pathfinding example:

http://www.scirra.com/forum/behaviorpathfinder_topic44444_page1.html
B
18
S
8
G
7
Posts: 120
Reputation: 5,625

Post » Thu Sep 15, 2011 10:24 pm

You can still do[code]*Mouse: Left button is down -> set X to Sprite.X+5[/code]or[code]*Mouse: Left button is down -> set X to Sprite.X+50*dt[/code]and for sprite going to mouse position you could do[code]*Mouse: Left button is down -> set X to lerp(Sprite.X,Mouse.X, 0.01)[/code]shinkan2011-09-15 22:26:30
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Sep 15, 2011 10:34 pm

PathFinder has no automated movement. 8dir has, sort of.

Automated Movement.capx
To restrict Y movement in this cap simply disable the conditions testing Y.


Also "such a common control interface" relies so much on what the dev wants (expect for his gameplay), that for it to be fully customizable, it is better if the dev does it himself.

(Or also what Shinkan said, ninja'd)

Kyatric2011-09-15 22:36:27
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Thu Sep 15, 2011 10:37 pm

8dir following a mouse looks kind of odd.
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Sep 15, 2011 10:44 pm

You can always set the 8dir behavior's angle in the properties to no.
It doesn't rotate and probably will look less odd to you.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Thu Sep 15, 2011 10:51 pm

The rotating is cool. It points in the direction it's moving.
B
18
S
8
G
7
Posts: 120
Reputation: 5,625

Post » Fri Sep 16, 2011 12:08 am

You could just give the object a bullet movement and always set its angle to face the mouse.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,468

Post » Fri Sep 16, 2011 8:14 am

Thanks for the help so far guys.
Kyatric that's almost there I reckon. It's just the "shaking" that's not ideal. I'll have to try edit it a bit more. Thanks a lot for this.

Ashley, I'll try the Bullet behavior as well. I think Construct 2 could use a behavior that simplifies this. I am trying to use Construct 2 as a type of point and click adventure game. Having behaviors that helps in this area would be a huge boon to me and I'm sure many others.
B
19
S
3
G
4
Posts: 79
Reputation: 3,711

Post » Fri Sep 16, 2011 2:46 pm

The bullet behavior only needs one event to get it to always move to the mouse (always - set angle to Mouse.X, Mouse.Y). Does that really justify a whole new behavior?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,468

Next

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, mnashwan, shinkan, stylie1, tarek2 and 10 guests