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 / Collison for jumping/landing

Author
Message
James Tighe
8
Years of Service
User Offline
Joined: 22nd Jul 2015
Location: Portsmouth, Hampshire, UK
Posted: 26th Jul 2015 14:07
Hi Guys,

Being new at this I have been attempting to create a simple platform game project. Utilising some the demo code and some of my own tinkering I have created a simple program where I can move a sprite around and jump using the physics commands.

I am having issues with collisions though.

I am trying to get the sprite to change to a jumping frame when the jump is initiated. I am doing this by setting the jump variable to 1 when the jump is initiated.



I cannot however get the sprite to detect contact with the ground to switch jump back to 0. I want to have it so when the sprite collides with the floor to change the spriteshapebox and set jump=0.

The trouble is I have tried this with this code



This seems to make the program automatically change jump=0 as the sprites are technically touching when the jump command is sent.

Is there any way to get the program to check for the collision with the ground only once the jump is initiated?

Full code below in case something else is wrong



Thanks in advance people

James
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 26th Jul 2015 16:07
maybe check the sign of the GetSpritePhysicsVelocityY
>0 the sprite falling
<0 the sprite goes up

or you need a state in air

AGK 108 (B)19 + AppGameKit (Steam) V2 Beta .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
James Tighe
8
Years of Service
User Offline
Joined: 22nd Jul 2015
Location: Portsmouth, Hampshire, UK
Posted: 26th Jul 2015 19:32
Thanks Marcus that worked a treat

I ended up changing the code to below.



This way it changes the sprite back to the standing sprite, changes the sprite box and sets jump=0 if the Y velocity is 0 and the sprite is in contact with the ground.

I sent ages looking at solutions and completely missed that!

Its slowly taking shape. The next part is to add tile based platforms and set the collision on them.

I'm really liking AppGameKit as it is easy to learn and the forum is very helpful and welcoming

Thanks again!

James

Brian Kuh: If anybody wants to see, there's a Donkey Kong kill screen coming up.

Login to post a reply

Server time is: 2024-04-26 18:03:38
Your offset time is: 2024-04-26 18:03:38