mouse click movement

Forum Home Forum Home > Construct 2 General > How do I....?
 Post Reply Post Reply Page  123 4>
Author
1,501 Rep
Post Options Post Options   Quote Havok Quote  Post ReplyReply Direct Link To This Post Topic: mouse click movement
    Posted: 15 Sep 2011 at 9:11pm
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.

Edited by Havok - 15 Sep 2011 at 9:18pm
Back to Top
2,846 Rep
Post Options Post Options   Quote Ghengis Quote  Post ReplyReply Direct Link To This Post Posted: 15 Sep 2011 at 9:57pm
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
Back to Top
9,197 Rep
Post Options Post Options   Quote shinkan Quote  Post ReplyReply Direct Link To This Post Posted: 15 Sep 2011 at 10:24pm
You can still do
*Mouse: Left button is down -> set X to Sprite.X+5
or
*Mouse: Left button is down -> set X to Sprite.X+50*dt
and for sprite going to mouse position you could do
*Mouse: Left button is down -> set X to lerp(Sprite.X,Mouse.X, 0.01)


Edited by shinkan - 15 Sep 2011 at 10:26pm
Back to Top

Moderator
28,570 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 15 Sep 2011 at 10:34pm
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)



Edited by Kyatric - 15 Sep 2011 at 10:36pm
Back to Top
9,197 Rep
Post Options Post Options   Quote shinkan Quote  Post ReplyReply Direct Link To This Post Posted: 15 Sep 2011 at 10:37pm
8dir following a mouse looks kind of odd.
Back to Top

Moderator
28,570 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 15 Sep 2011 at 10:44pm
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.
Back to Top
2,846 Rep
Post Options Post Options   Quote Ghengis Quote  Post ReplyReply Direct Link To This Post Posted: 15 Sep 2011 at 10:51pm
The rotating is cool. It points in the direction it's moving.
Back to Top

Scirra Developer
78,417 Rep
Post Options Post Options   Quote Ashley Quote  Post ReplyReply Direct Link To This Post Posted: 16 Sep 2011 at 12:08am
You could just give the object a bullet movement and always set its angle to face the mouse.
Back to Top
1,501 Rep
Post Options Post Options   Quote Havok Quote  Post ReplyReply Direct Link To This Post Posted: 16 Sep 2011 at 8:14am
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.
Back to Top

Scirra Developer
78,417 Rep
Post Options Post Options   Quote Ashley Quote  Post ReplyReply Direct Link To This Post Posted: 16 Sep 2011 at 2:46pm
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?
Back to Top
 Post Reply Post Reply Page  123 4>

Forum Jump Forum Permissions View Drop Down