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 / SetPhysicsGravity Problem

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 12th Dec 2014 11:22 Edited at: 12th Dec 2014 12:00
Hi.

I wrote a script that player can climb up and climb own from ladder. for climb the player i need use SetPhysicsGravity (0,0), but this work make other sprites that have Dynamic Physics fly on air. how can fix this Problem?

Thanks?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th Dec 2014 14:55
You need to set the velocity of the player sprite: SetSpritePhysicsVelocity
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 13th Dec 2014 11:14 Edited at: 13th Dec 2014 11:49
Quote: "You need to set the velocity of the player sprite: SetSpritePhysicsVelocity"


for climb up and down I used SetSpritePhysicsVelocity, but the Player can't climb up form ladder because there is "SetPhysicsGravity".but when use "SetSpritePosition", the Player can climb form ladder but can't stay on ladder.

this is my code that disabled all "SetPhysicsGravity(0,0)".

Please show me how can do it.

29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 14th Dec 2014 02:19 Edited at: 14th Dec 2014 02:20
Try this:



I don't use the physics commands that much but I think it's bad form to use the SetSpritePosition commands if you're using physics, as baxslash mentioned.

In the real world, ladders hold people up by providing a reaction force that is equal and opposite to the person's weight (newton's second law). The weight of the person is equal to their mass multiplied by gravity. So I added this into the code to stop the player falling back down the ladder if the player was not moving up.

This code isn't perfect as there's a bit of bouncing around when the sprite is on top of the ladder but I've seen worse in games I've played. There might be something clever that can be done to stop this happening.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Dec 2014 07:52
Thanks 29 games for your help.

but this way make player fly in sky and not have real physics.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Dec 2014 09:44
Honestly i would not use physics for a character if i were you. I have done it a few times but find it easier to set the character position manually myself.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 14th Dec 2014 10:04
I think we all said "Don't use physics" several times!

-- Jim - When is there going to be a release?
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 14th Dec 2014 11:32
Quote: "but this way make player fly in sky and not have real physics"


Really? It shouldn't do, unless you've changed the code.

Quote: "i would not use physics for a character"


I also read a comment of Jim's on another thread that mentioned that you don't need to use physics for most things which I'd agree with. I've not created anything that needed it, and I suspect that what Behdadsoft's attempting probably doesn't need it either, but doesn't this all hinge on what the game needs to do? Also, isn't there a case for people learning how these commands work?

I think some people might be using physics because it's an easy way to deal with simple collision, it detects and resolves the collision without any further code. Not using physics, it's easy to detect the collision but requires further work to resolve it.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Dec 2014 12:18
Quote: "I think we all said "Don't use physics" several times!"


Quote: "I also read a comment of Jim's on another thread that mentioned that you don't need to use physics for most things which I'd agree with.
"


if i don't use Physics my character fly in sky.
if you say don't use physics now how can make a real character that have real physic? (could jump, fall, ....)

I never didn't see this issue in other engines that don't use physics for character.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 14th Dec 2014 12:25
You do some programming. Sprites can move in any direction at any rate. People did platform games without physics for decades.

-- Jim - When is there going to be a release?
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Dec 2014 12:42 Edited at: 14th Dec 2014 12:43
Quote: "People did platform games without physics for decades"


yes, for NES and Sega there are several Platform games but this games Are made like Physics games. now i want know how can made a game like them that don't fly and can jump and fall? because make a game with AppGameKit is a Challenge for me.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 14th Dec 2014 13:35 Edited at: 14th Dec 2014 13:38
Your sprite can do whatever you want it to.

Just learn a bit more about programming and apply some maths. In Earth's gravity (ignoring air) a body will fall at a rate that increases at a rate of 9.81 metres every second. So if your character jumps off a ladder horizontally he will start at zero Y velocity.

But you need to have a scale factor. How high is the ladder in metres? Let's assume that it is two metres.

Let's assume a frame-rate of 60 FPS. For each frame you work out how many pixels that is in your world. Suppose that your scale is 100 pixels = 1 metre. The ladder is therefore 200 pixels high. At the end of the first frame he will have dropped approximately 1/60th of 100 pixels. In frame 2 he will drop a further amount. He's accelerating so he moves a bigger Y gap every time.

If you are going to use the physics you need to understand the physics, which you clearly do not. Because the steps on your ladder are a rigid body on the surface they apply an upward force of 1 g to any body standing on them. Unless the body has no mass it will stay there. The 1 g gravity is cancelled out by the 1 g negative force created by the step. A can of paint on a step is subject to a 1 g downward force and a 1 g upward force, so it is static in terms of the world view.

Going up steps using physics is highly complicated. You need to compute the impulse on the character and its vector. It's much simpler to do some elementary maths in relation to the situation. It's not hard. It just needs thinking about.

Here are some steps:

_
_
_
_
_

Going up or down the steps the character can simple just move to a step.

From the top step, the character goes to the right (steps off) then the character will begin to fall. Unless he's jumping off a mountain you might as well make the rate of fall constant (increase Y every frame by say 5) until he hits the ground.

Keep it simple.

-- Jim - When is there going to be a release?
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Dec 2014 13:55 Edited at: 14th Dec 2014 13:57
for any work you and other said read Examples. now I read AppGameKit Bitesize Tutorial for make platform game. then I begin make a game according to this example with more features. now you say me don't use this way. for this reason already said AppGameKit not have good example and tutorials.and in real projects, They have no effect.

Quote: "Just learn a bit more about programming and apply some maths
"


I think this Problem is not relate to programming. because Past experience at working with some 2d engines, all working with same method. and seem this is old method for make Platform game like NES and Sega games.and not seem good idea with now new technology.

However,please if I should change method show me your mean with an example.
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 14th Dec 2014 14:14 Edited at: 14th Dec 2014 14:15
I don't necessarily agree that you shouldn't use physics, I think you just need to learn exactly how to apply them. Take a look at 'Happy Chick - Platform Game' on the Google Play Store, this was made using AppGameKit v1, and uses Physics throughout. And seeing as it has had over 90,000 downloads, I think its pretty safe to say that it definitely works and is possible... (although it doesn't have ladders lol)

I'll have a look at this later (cooking my Sunday Roast at the minute) and see if I can come up with something...
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th Dec 2014 14:31 Edited at: 14th Dec 2014 14:32
Quote: "(although it doesn't have ladders lol)"


if i don't use ladder maybe no have any Problem.because before use ladder I no have any problem with use Physics.the biggest my problem is relate to ladder for now.

Quote: "I'll have a look at this later (cooking my Sunday Roast at the minute)
"


mmmmm...
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Dec 2014 17:30
If you're happy working with physics then that's fine. I'm not saying it's impossible to make a game using physics based characters, I wrote the bitesize tutorials. I just wonder if maybe you should start by understanding how to make a sprite move how you want it to before complicating things by using physics. If you'd rather carry on down this path that's fine too.

What in your code sets the position of your character? Where do you change the Y component? Look at these parts of your code and you'll discover why your character flies up in the air when their's no physics, you'll also see why he falls slowly WITH physics at the same time I imagine.
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 14th Dec 2014 19:07
It probably doesn't matter whether someone uses the physics engine or not, if they don't understand the real world fundamentals it's all going to be a little difficult.

It's about knowing simple concepts like how acceleration affects velocity, that mass and weight aren't the same thing, how the sum of the forces acting on a body relates to the final acceleration of that body and so on.

I'd say the only reason to use a physics engine is if there are complicated collision going on. Movement without collision can be done just as well using maths and it can be as simple or as complicated as you need.

I'd say baxslash is right, maybe simplify things now and then do something more complicated later.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 15th Dec 2014 15:19
I could fix fly in sky problem.

now I want wrote 29 games code with another method but when the Player climb up from ladder, and I release up key "GetRawKeyState = 0" the Player don't stay on the ladder and fall down. this is my code what is wrong?

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Dec 2014 15:52
Why are you setting a force and velocity for the sprite? One or the other (preferably velocity) should be fine. By setting a force and then setting the velocity you are cancelling out the force anyway.
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 15th Dec 2014 21:43 Edited at: 15th Dec 2014 21:51
@Baxslash

If you're refering to these lines in my original code:



Then the force simply takes the weight of the player. Without it the player just falls if they are not moving (i.e. if yevl# = 0.0). There are other ways of doing this, which I didn't explore, but it was late when I wrote it and it worked (at least on my computer).

@Behdadsoft
Your code doesn't compile and I don't think you've really understood my code.

But I think the main problem is this line

else if laddercollide = 1 and GetRawKeyState (38) = 1

If the upkey is released then GetRawKeyState (38) will equal zero so the if statement is false, regardless of whether laddercollide = 1, so the code does not execute the ladder climbing code.

I don't know what you expect this code to do. It feels like an over complication.

[edit]

Quote: " if i don't use Physics my character fly in sky.
if you say don't use physics now how can makea real character that have real physic? (could jump, fall, ....)"


I think I get it now, Behdadsoft doesn't actually know how to get the character to jump and fall and climb ladders without using the 2d physics commands. Is that correct?

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 16th Dec 2014 10:49
Quote: "Your code doesn't compile and I don't think you've really understood my code."


it's compile easily and don't show any error.i wrote it in AppGameKit v1.

I this is another code that I think it's similar your code.but I don't know why can't stay on ladder when up key is release.



Quote: "
I think I get it now, Behdadsoft doesn't actually know how to get the character to jump and fall and climb ladders without using the 2d physics commands. Is that correct?"


yes, right. because at first working with 2d engines I learn work with physics and all tutorials relate to Physics.
already said seem control character (fall, jump,...) without use Physics is old method like NES and Sega games. but i hope learn this method.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 16th Dec 2014 10:58
What if you made each rung out of a separate static-physics sprite but only turn on the physics for each rung if the player's Y position is higher than the rung. The built-in physics collision would then sort out all that "equal and opposite" physics stuff and it would probably be easier to program for a beginner (you just need a simple "IF PlayerY < RungY then setspritephysicson(rung,1)").

I'm beginning to think Behdadsoft is a TGC secret agent, sent to instigate coding debate amongst the community! Lol!

CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 16th Dec 2014 11:46 Edited at: 16th Dec 2014 11:46
The joys of physics glitches (this cracked me up):



JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 16th Dec 2014 12:22
That is brilliant - and right on topic!

-- Jim - When is there going to be a release?
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 16th Dec 2014 21:13 Edited at: 16th Dec 2014 21:13
Quote: "
What if you made each rung out of a separate static-physics sprite but only turn on the physics for each rung if the player's Y position is higher than the rung. The built-in physics collision would then sort out all that "equal and opposite" physics stuff and it would probably be easier to program for a beginner (you just need a simple "IF PlayerY < RungY then setspritephysicson(rung,1)")."


Hi CJB and Thanks for your idea. I think this way is not clean way. because I should for every PlayerY turn on or off Physics and other thing relate to physics that make increase script line and exist mistake in big code and also maybe exist once more ladder that help to Confused.
I think should there is another easiest way for use this method.

Quote: "
I'm beginning to think Behdadsoft is a TGC secret agent, sent to instigate coding debate amongst the community! Lol!"


It may be...Lol.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 17th Dec 2014 22:07
any idea?
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 18th Dec 2014 11:52 Edited at: 18th Dec 2014 11:55
I understand 29 games code and could write it again:



i Think
make sprite stay on the ladder at any Y position when "laddercollide = 1". and instead of disable Gravity should add a force to custom direction (X or Y). it's correct?
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 18th Dec 2014 16:07
Interesting stuff. Personally, I'd stick with just moving the sprite up and down the ladder (with suitable 'ladder climbing' animation of course). Why try to fudge the physics system to do something so simple? Each to their own. I look forward to seeing your final solution!

Wouldn't it be cool if you could turn off Gravity to climb a ladder in real life!?


Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 18th Dec 2014 19:56
this is my new code that used "SetSpritePhysicsON" and "SetSpritePhysicsOff" for stay on the ladder. and used "SetSpritePosition" instead of "SetSpritePhysicsVelocity". but I there is a Problem, that the player no have Real physics after collide with other objects.

Login to post a reply

Server time is: 2024-11-25 13:36:02
Your offset time is: 2024-11-25 13:36:02