Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How would i make a physics sprite apear to jump

Author
Message
Zubby1970
AGK Backer
15
Years of Service
User Offline
Joined: 22nd May 2008
Playing: AGK Studio Always
Posted: 9th Jan 2012 23:37
How would i make a physics sprite apear to jump, and still keep its forward momentem i have a bike going forward and want to make it jump. which command would be the best to use.

There can only be one
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th Jan 2012 23:53
Look at the "impulse" commands. Add a negative "Y" force and you'll get what you're after.

greenlig
20
Years of Service
User Offline
Joined: 30th Aug 2003
Location: Melbourne
Posted: 10th Jan 2012 07:56 Edited at: 10th Jan 2012 07:56
Throw this code in....



Replacing "Sprite" with your sprite's ID. Play round with the -10 variable, and you should get a jump happening, although it all depends on how you set up the universal gravity.

Hope that helps,
Greenlig

EDIT: Press Space to jump!

Your signature has been erased by a mod as it is far too big.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Jan 2012 08:03
Or you can use:
setSpritePhysicsVelocity(spriteID,getSpriteVelocityX(spriteID),-20)

...but again the-20 is a guess.

milhaus
20
Years of Service
User Offline
Joined: 7th Apr 2004
Location:
Posted: 10th Jan 2012 14:24
You also have to know when the jump is finished so you can allow another one, otherwise you can end up with a jetpack effect. I tried (roughly)

if GetSpriteVelocity(sprite) = 0
then allow another jump

This didn't really work very well as it seemed to take an age for velocity to reach 0, even with no bounce, resulting in the controls seeming unresponsive. I only had a quick look at it though, so if anyone has any better suggestions to find out if a jump has ended i'm all ears!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Jan 2012 17:28
Quote: "This didn't really work very well as it seemed to take an age for velocity to reach 0, even with no bounce, resulting in the controls seeming unresponsive. I only had a quick look at it though, so if anyone has any better suggestions to find out if a jump has ended i'm all ears!"

A better way of doing this would be to check for a contact with a "ground" sprite.

milhaus
20
Years of Service
User Offline
Joined: 7th Apr 2004
Location:
Posted: 10th Jan 2012 18:39
In my case it's miscellaneous debris that can be lying around, such as blown up platforms, barrels etc. Jumping from the ground or another static sprite works fine!

I was considering a dummy sprite attached to his feet to register collisions. I don't think it'd be perfect but it would be better than what I have.

If it wasn't for Jetpack Joyride i'd give him a jetpack and be done with it!
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 10th Jan 2012 21:18
How about something like this? No media needed, just copy and paste and see what you think. I assume you have the left and right momentum sorted? If not, I'd suggest using impulse also...

Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 28th Feb 2012 22:32
Sorry to resurrect this post, I'm wondering if anyone has any other suggestions for 'jumping', or more specifically knowing when to allow a jump and when not... I've tried the following two approaches;



This works well, until (like Milhaus says) there is debris laying around or I introduce other platforms etc. Checking for collisions against everything just isn't working...

The 2nd approach is;



This works ok, but quite often when running around even on flat ground the velocity isn't actually '0' so it appears unresponsive.

Does anyone have any other ideas other than these two?

Many thanks!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Feb 2012 22:42 Edited at: 28th Feb 2012 22:42
The first is the best solution of the two but is the problem that you are able to jump when standing on anything even debris? If so then just make sure you put all your ground sprites in a specific group IE. setSpriteGroup(spriteID,1) and use a raycast on that group starting at the centre of your character and extending just below him:


...obviously this could be optimised a little but you get the idea?

Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 28th Feb 2012 23:06
Ray Cast? Ok, that sounds interesting, I haven't experimented with Ray Cast yet, I'll give that a try... Thanks Baxslash, as always...
Zubby1970
AGK Backer
15
Years of Service
User Offline
Joined: 22nd May 2008
Playing: AGK Studio Always
Posted: 27th Apr 2012 01:44
in the end I had a counter count up and when it gets to a set value you can jump again

There can only be one
kamac
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 27th Apr 2012 09:41 Edited at: 27th Apr 2012 09:44
Here is how movement is handled in Spell Breath:




And here's jumping:



I have used not too effective method when checking if the user is on the ground (three raycasts, one on his left, another to his right and last in great center of it), but it works.
Maybe that'll help

(After removing all agk:: and ; you get BASIC code)
( || is OR, && is AND )

DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 27th Apr 2012 15:59
Al this talk of ray casting is okay, but I tend to try to keep things simple. A hidden sprite or sprites by his feet can do the same job with less hassle. Sprite groups, as baxslash said are great for deciding what will be a platform or a background object etc for avoiding certain objects.

Also in a jump you can check if you are in the upward arc or the downward arc and adjust collisions on the fly. Only let your character jump if you have landed, if he is jumping ignore the jump button. It should be as simple as setting a flag really.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 27th Apr 2012 16:15 Edited at: 27th Apr 2012 16:16
I find raycasting a simple and easy way of testing for this kind of thing. It's not really very complicated and blindingly fast. It's just a different way of getting the same information.

I was testing a raycast engine using over 300 raycasts per loop and it worked very fast and very well.

Checking velocity of your character is OK but you have to be sure that you aren't just at the top of your arc when you jump again, that's where raycasting or collision checks come in useful.

What I love is the fact there are so many ways to achieve a simple platformer engine in AppGameKit The more I use it the more I love it!

EDIT: raycasting returns normal values so you can check the slope your character is on too

Login to post a reply

Server time is: 2024-05-04 14:30:33
Your offset time is: 2024-05-04 14:30:33