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 / jumping code using physics

Author
Message
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 17th Jun 2015 15:50
Has anyone got any good platform jumping code,tried it myself:


but the player seems to stick to the sides of static 'walls' and such, I am guessing you would use something else also like raycasting but not sure how to do it correctly and reliably.

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 17th Jun 2015 16:23
It's probably due to using setspritephysicsvelocity rather than letting the physics engine set the velocity. Try adding an impulse to the velocity for your virtual joystick control instead of directly setting the velocity.

V2 T1 (Mostly)
Uzmadesign
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 17th Jun 2015 16:49
You'll probably find that you experience the same issue with impulse. What you need to do, is stop applying a directional force when you have collided with a 'wall' or 'platform' etc. For this I'd use raycasts.

Cast a ray slightly longer than your character by a couple pixels, and then use this to check for collisions with the wall... I normally use the same group number for all my ground/wall sprites and then use RaycastGroup...

I may have some sample code somewhere if you get stuck... Let me know.

Using AppGameKit V2 Tier 1
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 17th Jun 2015 16:58
hmmmm..anyone got an example,read up impulse but not sure! just a few boxes and a jumping box would do,as long as it doesn't stick during jumping! I just want to add to a editor I am working on, pretty busy adding other things,just got the editor to run the level within the editor itself, you can exit the running level and it goes straight back to where you was editing last, adding a lot of cool stuff but it is a lot of work, eventually I want to have a controller option within the editor,whether that be tilt or virtual joystick or physical, everything with editable params, which is my task after I finished the built in animation editor which I have just started!

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 17th Jun 2015 18:24 Edited at: 17th Jun 2015 18:39
Here's a little example I just whipped up (using impulse ):



V2 T1 (Mostly)
Uzmadesign
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 17th Jun 2015 19:05
That's a good example, and one I can't get my head around lol... I had assumed that constantly applying an impulse would have the same affect as applying a constant velocity... But I guess not... Good skills

Using AppGameKit V2 Tier 1
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 18th Jun 2015 10:36 Edited at: 18th Jun 2015 10:38
perfect CJB! thanks for that,ain't been too well so only just got chance to test it.. After I woke up and puked.. hah!.... but thanks man!

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 18th Jun 2015 11:09
hmm.. I haven't been placing my sprites within the editor using offset, so it doesn't work as it is now, unless there is another solution I need to change how the sprites are placed

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 18th Jun 2015 12:31
okay I have changed everything to offsets and all is okay,apart from.. how do I make sure the sprite cannot continue jumping when 'off ground'? but again not get stuck to some side

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 18th Jun 2015 12:35
You should be able to test for a collision. Only execute the jump code if the player sprite is touching your land/building sprites.
Good luck! I look forward to seeing your game - have you got a WIP thread in showcase yet?

V2 T1 (Mostly)
Uzmadesign
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 18th Jun 2015 13:06
this is jump code example from Markus at below link:

http://forum.thegamecreators.com/?m=forum_view&t=212989&b=41

shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 18th Jun 2015 13:16 Edited at: 18th Jun 2015 13:34
thanks everyone for the help! I will do a youtube video of what I am trying to achieve, which is basically a editor to do everything.... I had coded a tutorial before on some editor, but after serious examination of the code and experience showed me the code was actually junk! So I started another with the aim of making it much more flexible, I have took the attitude that if something is repeated more than once it belongs in a function, so I have functions like :


This makes for a much more manageable project and the development is much more rapid when done correctly! I guess this comes with experience and one must accept a justified rewrite of the whole code.

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 18th Jun 2015 14:10 Edited at: 18th Jun 2015 14:23
Okay... Here is a video of what I am doing! hope you like it. of course the player shouldn't rotate coz I set it not to! but I dunno..will look into it

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 18th Jun 2015 15:34
You can embed youtube vids here using youtube tags like this:







V2 T1 (Mostly)
Uzmadesign
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 18th Jun 2015 16:02
ah, ok..thanks.

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Jun 2015 13:37 Edited at: 19th Jun 2015 13:41
thanks again anyhow,got chance to look at the examples,with that bit of info and a bit of experimenting I came up with simply this:



here the player cannot jump unless r#=0, which I set to get the physics velocity y value, it will equal 0 when it lands on a tile anyhow, with the use of the floor command of course. Simpler than I dreaded!

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 19th Jun 2015 13:48
Great work Shadey! Thanks for sharing your solution! So simple

... Now can you get it to work with ladders???

V2 T1 (Mostly)
Uzmadesign
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Jun 2015 14:02
screw that! lol

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Jun 2015 14:44 Edited at: 19th Jun 2015 15:04
A slightly improved version:



I noticed sometimes it didnt jump,well after studying a few values I noticed that the velocity Y alternated from 0 to -0, so I have done this to counter that with a few extras! :/

**** Ironically down to ya basic binary of a 0 and a 1

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 19th Jun 2015 15:01
Quote: "it will equal 0 when it lands on a tile anyhow"


The problem you 'may' have with this method is that the Y velocity will also be 0 at the very peak of the jump, so technically possible to perform multiple jumps if you time it correctly...

Using AppGameKit V2 Tier 1
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Jun 2015 15:06 Edited at: 19th Jun 2015 15:07
hah! you are quite right on further inspection,so one must be able to jump only if you are not already jumping and no contacts have been found..ok lets try that! It is a good accidental find for a way to get a double jump powerup though.. lol

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 19th Jun 2015 15:12
Quote: "so one must be able to jump only if you are not already jumping and no contacts have been found"


Lol, give it a try, but I'll be honest, I've been down this same road. I tried everything to get it to work and the only thing which worked flawlessly was a raycast down through his feet... Using the raycast to detect ground contact.

Using AppGameKit V2 Tier 1
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Jun 2015 15:20 Edited at: 19th Jun 2015 15:22
hmm..that way doesn't work if you hug a wall when jumping..will have to think about this.

*** Edit ***

Yeh I think you could be right, will have to use raycasting!

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 19th Jun 2015 15:22
If you want to see the 'Raycast' method, let me know and I'll throw something together...

Using AppGameKit V2 Tier 1
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Jun 2015 15:53
ah,yes please! just tried it myself with a fail,it would jump sometimes but not..again!!

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 19th Jun 2015 16:26 Edited at: 19th Jun 2015 16:27
Here's a thrown together example, apologies, I have used a different method of moving the character, but just concentrate on the Raycast bit...



What I have done, is assigned the ground sprite a group number, in this case 1. I then perform the PhysicsRayCastGroup command for this group number only. The ray starts at the very center of the character and continues down through his feet and 5 pixels further. 'RCDown' then stores the result of this and returns a '1' if a sprite of group 1 is detected... Hope that makes sense...

EDIT: The difference here is I am performing a ray against specific sprites i.e. only sprites I deem to be ground. In your method, any sprite would allow you to jump...

Using AppGameKit V2 Tier 1
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Jun 2015 16:26 Edited at: 19th Jun 2015 16:39
okay I had another look and came up with this code using raycasting:




*** edit ***
Actually thinking about it just +3 at the end will suffice,more exact!
so


Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 19th Jun 2015 16:27
ah sorry..was working on it at the same time as you,if mine fails then I will sure use yours! thanks again

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 20th Jun 2015 12:56
okay I spent ages getting this sorted, basically I had an idea when writing the editor that I would want different 'tile values' So these were put in place. which allowed me to do:




the value of platobj[ide].tilevalue is already set in the editor via an edit box. So I then simply check if button was pressed and jumping=0. Works well so far, but then again everything else seemed to!

Hail to the king, baby!
http://davidjohnwheeler.blogspot.co.uk

Login to post a reply

Server time is: 2024-11-25 21:25:31
Your offset time is: 2024-11-25 21:25:31