[Solved] ...script a movement from A to B

Get help using Construct 2

Post » Wed Jan 08, 2014 5:34 pm

Hi there,

I have an object that I want to animate statically. I have a fish in a fishbowl that needs to swim to the left and to the right and back and forth for ever.

Ideally it would be great to have him randomly drift up and down a little as well as left and right.. but most important is just knowing how to script an object to be able to go to a specific x/y coordinate and back to another. I think I can manage the flipping logic and all that.. its really just about how to tell

My instinct was to use bullet, but that just wants go at a fixed speed and not care about location. I would really love to be able to use easing.. in and out.. so the fish isn't just moving at a fixed speed, but rather speeding up and slowing down as it turns around going back the other way.

Thanks!
Caleb

part12studios2014-01-13 16:27:46
B
59
S
9
G
1
Posts: 946
Reputation: 6,561

Post » Wed Jan 08, 2014 5:37 pm

Sine behaviour is what you are looking for.
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 » Wed Jan 08, 2014 7:50 pm

yea that does do the trick, but what about interpolating to specific locations?   this is a great simulation for the fishtank for sure, but i feel like this doesn't offer a lot of control.

another situation that i though would be related to this was if i wanted to have the fish move over to one side and stop.. then maybe in a given condition, then move to another spot with easing in/out.

I did apply the sign suggestion and it worked well, but i was wanting to have a little more control over other situations.

Thanks!
Caleb
B
59
S
9
G
1
Posts: 946
Reputation: 6,561

Post » Wed Jan 08, 2014 8:05 pm

You can do a lot with lerp (linear interpolation)

I don't have an example at the moment, but there are many on the forum.
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 » Thu Jan 09, 2014 3:04 pm

ok i'll search around for it.   I've never come across a behavior called that.   thanks for the tip! :)
B
59
S
9
G
1
Posts: 946
Reputation: 6,561

Post » Thu Jan 09, 2014 3:38 pm

lerp isn't a behaviour, it's an expression you can use.

create an object and use this:

every tick - object set x : lerp(object.x,1000,0.1)

to see the effect.
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 » Thu Jan 09, 2014 8:33 pm

I would use the stuff from the Platformer tutorial, Enemy Movement. Should work perfect for what you are trying to do.

https://www.scirra.com/tutorials/253/how-to-make-a-platform-game/page-7
Image
B
47
S
17
G
3
Posts: 206
Reputation: 5,061

Post » Fri Jan 10, 2014 3:46 am

@LittleStain, Ok I was able to make that expression work so yea that's very cool. I'll see what I can do with that now that i've seen it work.

@VictoryX that is a way to do it and that does give me some ideas, but it wouldn't allow me to slow down the object as it approaches the edge to trigger a turn around event.
B
59
S
9
G
1
Posts: 946
Reputation: 6,561

Post » Fri Jan 10, 2014 3:55 am

To slow down the object as it approaches just reduce the movement speed every tick if distance between object and edge is below a certain value.
B
47
S
17
G
82
Posts: 2,230
Reputation: 48,607

Post » Fri Jan 10, 2014 2:15 pm

yea I really like the idea of using lerp because i really just want to say move HERE and give it an X and Y value and be done with it.

Relying on colliders to trigger events does sound like a great idea like in the case of the platformer for sure. I have used similar approaches with GameSalad, but interpolating with easing is something that is also equally helpful

Thanks for the great advise and feedback!

B
59
S
9
G
1
Posts: 946
Reputation: 6,561

Next

Return to How do I....?

Who is online

Users browsing this forum: matriax and 25 guests