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

Just started using Construct 2? Post your questions here

Post » Sat Aug 30, 2014 8:02 pm

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?
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 8
Reputation: 218

Post » Sat Aug 30, 2014 8:11 pm

Rotate clockwise + pathfinding behavior maybe.
B
22
S
9
G
7
Posts: 421
Reputation: 6,543

Post » Sat Aug 30, 2014 8:24 pm

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

ClampTapLeftRightMove.capx


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.

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
You do not have the required permissions to view the files attached to this post.
Find all the Construct 2 games that were on Steam Greenlight here
B
33
S
9
G
7
Posts: 451
Reputation: 6,782

Post » Sat Aug 30, 2014 8:50 pm

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 told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Aug 31, 2014 7:33 am

OddConfection wrote:@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.

ClampTapLeftRightMove.capx


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.

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
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 8
Reputation: 218

Post » Sun Aug 31, 2014 7:39 am

LittleStain wrote: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.
B
4
Posts: 8
Reputation: 218

Post » Sun Aug 31, 2014 8:26 am

Go48Games wrote: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.
Find all the Construct 2 games that were on Steam Greenlight here
B
33
S
9
G
7
Posts: 451
Reputation: 6,782

Post » Sun Aug 31, 2014 9:04 am

OddConfection wrote:
Go48Games wrote: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
B
4
Posts: 8
Reputation: 218

Post » Sun Aug 31, 2014 5:55 pm

OddConfection wrote:
Go48Games wrote: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"
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 8
Reputation: 218

Post » Sun Aug 31, 2014 7:15 pm

@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.
Find all the Construct 2 games that were on Steam Greenlight here
B
33
S
9
G
7
Posts: 451
Reputation: 6,782


Return to Beginner's Questions

Who is online

Users browsing this forum: rbailey83 and 1 guest