mouse click movement

0 favourites
From the Asset Store
Click! Click! 136 click sounds for your video games or media projects
  • 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. <img src="smileys/smiley9.gif" border="0" align="middle" /> 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.

  • 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

  • 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)
  • 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

  • 8dir following a mouse looks kind of odd.

  • 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.

  • The rotating is cool. It points in the direction it's moving.

  • You could just give the object a bullet movement and always set its angle to face the mouse.

  • 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.

  • 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? <img src="smileys/smiley5.gif" border="0" align="middle" />

  • I think he meant something for beginners - simple behavior that makes sprite follows the mouse cursor or or goes smoothly to mouse position after left/right clicked.

  • I think he meant something for beginners - simple behavior that makes sprite follows the mouse cursor or or goes smoothly to mouse position after left/right clicked.

    I did yes, thanks shinkan. Ashley I understand what you are saying in terms of the Bullet behavior. Maybe it could be something we can build upon? From other apps I have looked at it is an obvious behaviour to add.Just remember every noob might come here looking for the same thing and might not really think of using the Bullet behaviour for a player walk behaviour.

    A built in behaviour like that with a "Go to and stop" "go to and activate" (where it could launch a different "script" or cobine with a path-finding behavior) could be really powerful and speed up development quite a bit.

  • 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? <img src="smileys/smiley5.gif" border="0" align="middle" />

    The other problem I'm having with this (Using the Bullet Behavior for movement) is that the Sprite stops but is "jumping erratically" at this point. like it's flickering with every tick.

    I've tried to come up with a way to check what the previous Mouse click X and Y, programatically I know what I need to check for and what needs to happen, but can't seem to figure that out with the behaviour / event system.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Stop the the bullet movement once it's within a few pixels of the target. You could use the distance() expression to calculate if it's very close.

  • Where do you put the distance calculations? In a separate event, as a new condition in the same event, or as another action in the same event?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)