Pages: 1
  Print  
Author Topic: Make sprite run through a loop (like sonic)  (Read 3007 times)
Offline (Male) edsquare
Posted on: July 17, 2014, 12:21:35 PM

Member
Location: The throne of ringworld
Joined: Apr 2014
Posts: 402

View Profile
Already went to google for some help but I cant seem to find anything (maybe my search is faulty).  :ohdear:

The goal is to make a character/sprite run on a surface that loops without the character falling if it has the right speed, I suposse it would have to be done by a mathematical formula in the script.  :o

Trouble is to find said formula and then to adapt it to the script. I only find references to a logical loop and that is not what I need and besides I already know how they work.  :)
Logged
A child of five would understand this. Send someone to fetch a child of five.
Groucho Marx
Offline (Unknown gender) Darkstar2
Reply #1 Posted on: July 17, 2014, 01:52:30 PM
Member
Joined: Jan 2014
Posts: 1244

View Profile Email
I'm sure you know about the angle and direction, speed and traction aspect to achieve this.  The way I would do it is if a certain speed is not achieved the character cannot go past the bend, so they would not be able to loop around in the first place......  IF the speed is right the character continues past the bend and angles up the loop, without falling down providing momentum is maintained, I normally use flags when doing stuff like that (onground, inair, isjumping, is falling, isfastenough, etc.etc.)  :P
Logged
Offline (Unknown gender) TheExDeus
Reply #2 Posted on: July 17, 2014, 01:53:12 PM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
Usually you have to use more sophisticated physics simulations if you want this to work correctly (like Box2D), but you can of course just code a simple code where there is only a speed threshold involved. Like if the guy is running 20 pixels per frame (speed), then when hitting the loop, do either a sprite animation or a image_angle thing together with lenghtdir_x/y for placing him on radius. If the speed is lower than make him end running proportionally faster.
Logged
Offline (Unknown gender) Darkstar2
Reply #3 Posted on: July 17, 2014, 01:58:20 PM
Member
Joined: Jan 2014
Posts: 1244

View Profile Email
Usually you have to use more sophisticated physics simulations if you want this to work correctly (like Box2D), but you can of course just code a simple code where there is only a speed threshold involved.

Well of course you can do that with physics, but for those who don't know how, the DIYS method is simpler.  I personally would use the lazy approach and do it myself rather than use physics, given there is no IDE controllable physics in LGM, you have to do everything yourself, would probably be more time consuming than speed/traction/angle/direction along with some variable manipulation and condition checks :D

Quote
Like if the guy is running 20 pixels per frame (speed), then when hitting the loop, do either a sprite animation or a image_angle thing together with lenghtdir_x/y for placing him on radius. If the speed is lower than make him end running proportionally faster.

Why not an image_angle combined bound to direction, I personally never used lengthdir_x/y, what does that do ?
Logged
Offline (Unknown gender) TheExDeus
Reply #4 Posted on: July 17, 2014, 02:02:30 PM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
http://enigma-dev.org/docs/Wiki/Lengthdir_x
Logged
Offline (Unknown gender) Darkstar2
Reply #5 Posted on: July 17, 2014, 02:06:30 PM
Member
Joined: Jan 2014
Posts: 1244

View Profile Email
lol! Yes I know about the docs Harri I am still a little confused on its uses though as there are other ways of achieving the same, I've always used angle, speed, direction, traction. (movement), what are some examples of use with length_dir, in english terms, not just one example in the docs. :D

Regarding the sonic example and what OP is asking, how would length_x/y fit into the equation in terms of movement ?

Logged
Offline (Unknown gender) TheExDeus
Reply #6 Posted on: July 17, 2014, 03:11:05 PM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
lengthdir_x/y returns a position length "len" away at direction "dir". So using this you can make rotation around point. These functions allow you to take the loop radius, it's center and make the guy go around it. I use it basically in every possible project, because it has millions of uses - from making something shoot at certain distance, to making a tornado.
Logged
Offline (Male) edsquare
Reply #7 Posted on: July 17, 2014, 04:08:11 PM

Member
Location: The throne of ringworld
Joined: Apr 2014
Posts: 402

View Profile
@Darkstar2: Thanks mate! not sure about the implementation yet but will give it a shake trying your tips.   :eng101:

@TheExDeus: Thanks bro! Will have to check that x/y stuff myself, and also box2d.  :eng101:

As you may have guessed this is for my remake of Open Surge on Enigma.
Logged
A child of five would understand this. Send someone to fetch a child of five.
Groucho Marx
Offline (Unknown gender) TheExDeus
Reply #8 Posted on: July 17, 2014, 04:22:57 PM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
You can also look at this - https://www.youtube.com/watch?v=Q9WJDy02LUs (https://www.sendspace.com/file/wbh4kw)
It doesn't have loops though.
Logged
Offline (Male) edsquare
Reply #9 Posted on: July 17, 2014, 05:20:50 PM

Member
Location: The throne of ringworld
Joined: Apr 2014
Posts: 402

View Profile
You can also look at this - https://www.youtube.com/watch?v=Q9WJDy02LUs (https://www.sendspace.com/file/wbh4kw)
It doesn't have loops though.

That game doesn't have loops true but sonic runs around a circle, from the outside!

Downloaded the engine, its a gmk, how can I see the code or D&D they used in it?
Logged
A child of five would understand this. Send someone to fetch a child of five.
Groucho Marx
Offline (Unknown gender) TheExDeus
Reply #10 Posted on: July 17, 2014, 05:46:41 PM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
You can just load a gmk. It's a GM file format.
Logged
Offline (Male) edsquare
Reply #11 Posted on: July 17, 2014, 05:56:04 PM

Member
Location: The throne of ringworld
Joined: Apr 2014
Posts: 402

View Profile
You can just load a gmk. It's a GM file format.

yea I know that, what I want to know is how to see what they did to make it work.

As when you open a C++ file, if you know the language you can read it (If it's well commented)  ::)
Logged
A child of five would understand this. Send someone to fetch a child of five.
Groucho Marx
Offline (Male) Josh @ Dreamland
Reply #12 Posted on: July 17, 2014, 10:36:25 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
If you are looking to calculate the speed you must be going, you can do that by comparing the centripetal acceleration to your gravitational constant. The centripetal acceleration is given by sqr(speed) / loop.radius. So assuming you're using a gravity constant of one pixel per frame per frame, all you want is if (sqr(speed) / loop.radius < 1) path_end(loop.path);, or whatever logic you need to stop following the loop.

You'll probably find that this calculation is too realistic for your actual game to be able to use it, (it turns out you have to be moving pretty damn fast to stay on a loop by your own force), so feel free to tone down the gravitational constant for that equation. :P
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) edsquare
Reply #13 Posted on: July 17, 2014, 10:57:09 PM

Member
Location: The throne of ringworld
Joined: Apr 2014
Posts: 402

View Profile
If you are looking to calculate the speed you must be going, you can do that by comparing the centripetal acceleration to your gravitational constant. The centripetal acceleration is given by sqr(speed) / loop.radius. So assuming you're using a gravity constant of one pixel per frame per frame, all you want is if (sqr(speed) / loop.radius < 1) path_end(loop.path);, or whatever logic you need to stop following the loop.

You'll probably find that this calculation is too realistic for your actual game to be able to use it, (it turns out you have to be moving pretty damn fast to stay on a loop by your own force), so feel free to tone down the gravitational constant for that equation. :P

Thank you!

You sir a a true scholar and a gentleman!  :)
Logged
A child of five would understand this. Send someone to fetch a child of five.
Groucho Marx
Pages: 1
  Print