Jumping from one position to another
BonepileGames
Member Posts: 194
Hello to GS Community,
I would like to ask you if you can give me any ideas about an object jumping from one point to another continously as shown in the picture below.
I tried interpolating object's X and Y but it moves in a straight line. I guess I have to code it like it should semi-orbit around a point but cannot figure it out.
Any ideas will be greatly appreciated.
Thank you
Comments
Constrain position X to AAA * cos((self.time*BBB)%180)+CCC
Constrain position Y to AAA * sin(self.time*BBB)+CCC
. . . . . .
AAA = radius of semicircle
BBB = speed
CCC = centre of semicircle
Thank you, @Socks
You led me to the right direction. Having written your idea, it started from one point and making semi-circle from right then spawning again from the initial point making semi-circle from left repeatedly.
However, I needed something else.
Constrain position Y to AAA * sin(self.timeBBB)+CCC
Constrain position X to AAA * cos(self.timeBBB)+DDD
Constrain position Y to AAA* sin((self.time*BBB)%180)+CCC
Where:
AAA radius of semicircle
BBB speed
CCC centre of semicircle (regarding Y-axis)
DDD centre of semicircle (regarding X-axis)
Thank you once again, Socks
@BonepileGames
Three constrains !??!?
I accidentally, put the %180 on the wrong axis, all you need is this:
. . .
Constrain position X to AAA * cos(self.time * BBB)+CCC
Constrain position Y to AAA * sin((self.time * BBB)%180)+CCC
Actually, it works perfectly with those two of yours.
I haven't noticed if I turn my first constrain off it would be the same thing.
@BonepileGames
P.S. if you want it to start from the left (rather than the right), just offset the angle that cosine is working on (by 180°), so something like this:
Constrain position X to AAA * cos(self.time * BBB+180)+CCC
Constrain position Y to AAA * sin((self.time * BBB)%180)+CCC
@Socks
Do you know of any way to make it move in semi-sphere where the sphere is not perfect circle, something like in the picture below.
Just reduce the width it travels . . . or increase the height it travels.
So . . .
Constrain position X to AAA * cos(self.time * BBB**)+CCC
Constrain position Y to AAA * sin((self.time * BBB)%180)+CCC
. . . .
Normal semicircle: (iPad Landscape)
Constrain position X to 200 * cos(self.time * 100)+512
Constrain position Y to 200 * sin(self.time * 100)+384
. . . .
Taller semicircle: (iPad Landscape)
Constrain position X to 100 * cos(self.time * 100)+512
Constrain position Y to 200 * sin(self.time * 100)+384
So it goes 100 pixels left to right - and 200 pixels up and down.
or
Constrain position X to 200 * cos(self.time * 100)+512
Constrain position Y to 345 * sin(self.time * 100)+384
So it goes 200 pixels left to right - and 345 pixels up and down.
. . . . etc etc
Got it.
Thank you once again
@Socks
Could you give me a clue how to make an actor jumps in the following pattern:
Yeah, it's pretty straightforward, let me do a quick demo . . . . .
Here you go . . .
Shlinky dinky: https://www.mediafire.com/?v14cnyzymbcx8sa
How it's done: keep the up and down movement from the previous demo (constrain Y to blah blah blah) and simply move the actor from left to right, for this I used interpolate, but there are lots of other ways to do that part.
@Socks
I want to thank you for the demo but unfortunately the link seems to be broken. Is it possible to fix it up or reupload it?
Thank you
Are you able to say a little more than simply 'it's broken', i.e. what happens when you click the link, does it take you to Mediafire, if so does Mediafire say the file is not available or is missing or is private or something like that, or does your browser say the page doesn't exist ? . . . etc etc.
It works fine for me.
My browser said 'This page doesn't exist' 20 minutes ago.
However, I tried the link again and it seems to work.
Thank you, Socks!
It works great.
Good !
P.S if you want your actor to rotate correctly as it bounces (so it's angle follows the arch or the bounce) you can use this:
Constrain rotation to 60*cos( self.Time *100%180)
Obviously the '60' and the '100' parts should be whatever values you are using for your other constrain behaviour (the constrain behaviour Y one).
Example: https://www.mediafire.com/?9h62gox3h2mv6nr
Thank you, Socks!
Instead of your suggestion, I just used to 'Rotate' behaviour set to anti-clockwise at speed of 90, it fits well in my project.
I am curious if there is any way to wrap X on the scene and make that actor bounce continously. I tried to wrap X on the scene and changed the interpolate position x to 2048 for example, which means 2 times to go from left center to the right. However, when the actor goes to the screen for 2nd time it starts flashing.
Any ideas?
Yeah, rotate would work too, you'd need to set it to whatever the game.time multiplier is to keep it in sync, so with something like this . . .
60 * sin( self.Time *100%180)+200
You would make your rotation speed 100
Just dump the interpolation behaviour and use something like 'Move' . . . hold on, let me make a quick demo . . .
Demo . . . . ah, actually mediafire is down for some reason . . . so here's a screenshot:
(don't forget to switch scene:wrap:x on)
It was so close to mind. How couldnt I think of it? LOL
Thank you