How do I make a sprite slowly move to Mouse.X

0 favourites
  • 10 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • I want to make my sprite move from point A to B, the way it is now is, when I press on a place on the screen it INSTANTLY goes to the point where I clicked. You might have noticed I put the Instantly in caps lock. That's because I want it to"Roll" towards the position. (Slowly walk).

    I know I can create the roll effect by just rotating the sprite clockwise or counter-clockwise. But it has to "walk" toward the point where I clicked. I've tried alot of behaviors but haven't found what I needed.

    I also include an image for further explanation.

    On a side note how do I change the position of "what you can see" when you start the game?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Rotate clockwise + pathfinding behavior maybe.

  • Go48Games

    I made an example for someone else who wanted to move something left and right slowly to a point based on where the player tapped.

    It might be useful for you.

    [attachment=0:233u9gqo][/attachment:233u9gqo]

    Basically it's setting X position using lerp every tick to slowly move it to the destination with a clamp to make sure it doesn't go too far.

    [quote:233u9gqo]On a side note how do I change the position of "what you can see" when you start the game?

    You can use the actions System->Scroll to object/position/X/Y to move the camera, or alternatively, give a player character the ScrollTo behaviour

  • There are so many ways this could be accomplished using the standard behaviours it would be nice to know what your further plans are with the character so you get the best advice..

  • Go48Games

    I made an example for someone else who wanted to move something left and right slowly to a point based on where the player tapped.

    It might be useful for you.

    [attachment=1:2tqtkjqq][/attachment:2tqtkjqq]

    Basically it's setting X position using lerp every tick to slowly move it to the destination with a clamp to make sure it doesn't go too far.

    [quote:2tqtkjqq]On a side note how do I change the position of "what you can see" when you start the game?

    You can use the actions System->Scroll to object/position/X/Y to move the camera, or alternatively, give a player character the ScrollTo behaviour

    Thanks its exactly what I needed. To get it to work with my own sprite I tried to change to code from Sprite.X .... to Newsprite.X and everything else where "Sprite" was mentioned. I also added the 2 instance variables to my newsprite. But it doesnt seem to be working, what did I do wrong, did I forgot something?

    EDIT: the included image didn't seem to be displaying correctly: this is the imgur code : JQiqPZM.png

  • There are so many ways this could be accomplished using the standard behaviours it would be nice to know what your further plans are with the character so you get the best advice..

    I want my guy to roll over(on x-axis) to somewhere so it can catch stuff thats falling down.

  • Thanks its exactly what I needed. To get it to work with my own sprite I tried to change to code from Sprite.X .... to Newsprite.X and everything else where "Sprite" was mentioned. I also added the 2 instance variables to my newsprite. But it doesnt seem to be working, what did I do wrong, did I forgot something?

    In the Mouse on any click event, you need to set the instance variable Destination for the Newsprite not the blue sprite.

  • > Thanks its exactly what I needed. To get it to work with my own sprite I tried to change to code from Sprite.X .... to Newsprite.X and everything else where "Sprite" was mentioned. I also added the 2 instance variables to my newsprite. But it doesnt seem to be working, what did I do wrong, did I forgot something?

    >

    In the Mouse on any click event, you need to set the instance variable Destination for the Newsprite not the blue sprite.

    Thanks, stupid mistake. everything is working now

  • > Thanks its exactly what I needed. To get it to work with my own sprite I tried to change to code from Sprite.X .... to Newsprite.X and everything else where "Sprite" was mentioned. I also added the 2 instance variables to my newsprite. But it doesnt seem to be working, what did I do wrong, did I forgot something?

    >

    In the Mouse on any click event, you need to set the instance variable Destination for the Newsprite not the blue sprite.

    Ok so everything seemed to be working, until I noticed this problem. When I press at the left edge of my screen, my sprite goes to the edge of my screen(which is what I want) . But when I press on the right edge my sprite doesn't go to the edge of the screen. It only comes closer.

    The "eiland" sprite, does the same thing as the "newsprite"

  • Go48Games

    I'm not sure why it's not working, it seems to be set up the same as the example except for Mouse instead of Touch (using Touch would accept mouse clicks too with "Use mouse input" set to Yes)

    You asked about changing view position before, so is there any scrolling or scaling or layer parallax or anything like that in this Layout? Those can affect the Mouse.X values.

    You might need to use Mouse.X(Newsprite.LayerName) so it adjusts the Mouse.X value for that layer.

    If that doesn't help, you could send the Mouse.X value to a Text/SpriteFont object on click to confirm it's getting the right position.

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