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 / Sprites stuck inside each other

Author
Message
KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 12th Feb 2012 23:24
(firstly, sorry for spamming the boards - I was about to head off to bed, and given when this place seems busy, a lot of you are in another time zone so it made sense not to wait for my previous thread to be verified)

Here's a question. I've got a player sprite, with dynamic physics enabled, and a lot of "tile" sprites each set to be static physics objects.

At startup, the player sprite is in the centre of the screen. It falls and lands on some of the static sprites beneath it (the floor), however it tends to fall a few pixels through the floor.

I have an interaction set up where, when the player clicks the screen, the player sprite should move - but it can't, as it's intersecting with a floor sprite and refuses to move anywhere (sometimes it seems to wobble a bit if I click repeatedly, but it's definitely stuck).

I have gravity turned on, if that makes any difference.

What's the correct way to deal with this? Are you supposed to disable the physics and move the player sprite back a few pixels until it's just flush with the surface? How do I best go about doing that?

Thanks in advance for the help. I'm thinking this is probably quite a beginner problem that most people here will know how to solve, so I thought it better just to ask rather than spend hours scratching my head over it.
KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 13th Feb 2012 08:04
I would edit the prior post, but it doesn't appear I can.

This has now become my main problem - no idea how to tackle it. Any help explaining how I could fix it, or how I rework my methodology to prevent it would be much appreciated.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Feb 2012 08:18
This problem usually happens if

1. You create 2 sprites interlocked at the start
2. You manually create the physics shape incorrectly (e.g anticlockwise)
3. You manually move the sprite

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th Feb 2012 09:53
Any chance you could share some code?

bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 13th Feb 2012 12:39 Edited at: 16th Feb 2012 11:03
Quote: "I have gravity turned on, if that makes any difference."


Perhaps you have your mass turned up way too high for the character or your gravity is way too high.

I chose kg for my scale to enter for mass for each sprite. What I mean is, I guestimate the object's mass in kg and enter in using SetSpritePhysicsMass(). You can use whatever scale your want, pounds, grams, etc, just make sure it's sensible. You don't need to set mass for static objects, afaik.

Also make sure your gravity setting is correct and to the right scale.

KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 13th Feb 2012 20:11
OK, so what are good figures for the physics scale and Y gravity values?

I'm using 640x960 resolution, and my character is 64px tall, so I suppose at human average of 1.8m tall this gives me a screen scale of 0.028125m per pixel (or around 3cm).
KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 13th Feb 2012 21:15
Ah thanks all, I managed to fix it anyway. It was partially to do with the figures, and partially to do with the order I was initialising my physics settings at the start of the program. Straightened that out now and I have a block that I can move around and make jump like a platformer character.
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 16th Feb 2012 11:01 Edited at: 16th Feb 2012 11:03
Quote: "I'm using 640x960 resolution, and my character is 64px tall, so I suppose at human average of 1.8m tall this gives me a screen scale of 0.028125m per pixel (or around 3cm). "


Yep, that's exactly how I figured out my scale. I personally used 32px = 1 meter = 1 unit (chosen scale value), but you can do it however you want.

KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 16th Feb 2012 19:38
So Jericho, what settings did you use on that scale? As they'll be similar to what I'll need to use.
KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 16th Feb 2012 20:45
Just as a more general piece of advice, how do people tend to make platformer characters handle correctly?

I have two problems. The first is that my character jumps/falls too slowly.

In order to work out how a character should be moving at a given time, in the main loop I have a series of things (control inputs etc.) that store in two variables the force acting on the character in X and Y. Here's how I do it:



It works perfectly fine except for one problem. When I click the mouse button, the character sprite slows down significantly in the X, and jumps - but I want the sprite's X speed to remain unchanged as it jumps. It almost comes to a stop. This also happens if I "jump" whilst in the air, so it has nothing to do with friction with the floor or anything like that.

Here's how it looks (wish I could say I drew that backdrop, but I got it after a quick Google, so I can't take credit for that!!)



So in that, the character is speeding to the right (the screen is also tracking it), you hit jump, and he slows to a crawl in the X as he speeds up.

I can't see anything in the above code that would cause this problem.

Can anyone advise me here?
KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 16th Feb 2012 20:48
Oh also, in addition to that code post above - I tried turning off the X force applied whenver the character's feet aren't on the ground - it stops dead in the X axis whenever the player jumps.

It's almost like I stop applying the force, and the sprite stops INSTANTLY - whereas I would have expected it to take longer. Anyone know what might be causing this?
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 17th Feb 2012 14:26 Edited at: 17th Feb 2012 17:39
Movement gets a bit complex and I won't be able to cover it all, but the scale I use is 1 meter per display unit. So if I set a sprite at position 1,1, they're 1 meter in and 1 meter down on the map. The sprite size I use is 2 by 2 square, meaning I can have characters up to 2 meters in height. I made a mistake when I told you my scale is 32x32, that's actually for my personal reference when making images, but in the engine, I use 1 meter per screen unit. I set the physics scale 1:1 with the display, and gravity I have set to -9.8.

My display aspect is 1:1 square, so I'll need to make adjustments later to make things display the way I want, but this is the setup I use for testing/development.

From there, I timed how long my character sprites take to reach terminal velocity (somewhere around 120mph) and set their friction so they could attain that speed in the required time (roughly 20 seconds). I know my physics are right because they match real-world expectations. Basically it looks right and my stopwatch says it's right.

As for jumps, I just apply a force on the sprite upwards, but only when his feet are on the ground. You can use a raycast from the middle of the sprite down to his feet, if you detect a sprite other than itself then you know you're on the ground.

Further, you only want to apply the force once, when the jump key is pressed, and then never again until the jump button is released.

When my sprites move left and right, I apply a force. When the characters stop moving left and right, a apply a force in the opposite direction with the same amount of force the character is currently moving minus 1/4. This allows the character to stop very quickly.

To give a character a speed limit, I just choose a top-speed and apply the same kind of forces to keep him going at that same top-speed. (His legs can only move so fast, afterall)

You have to be careful with moving a character like this because it could end up being frame-rate dependent. On differeing frame rates it may take longer/shorter for a character to stop. I solve this by just making sure I apply forces on a consistent rate regardless of framerate.

You don't want to use friction to stop a character cuz that'll mess everything else up. Your characters have feet that are good at stopping, they are not rolling balls

KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 18th Feb 2012 00:18
Thanks again Jerico. I managed to fix my problem by using getVelocity and setVelocity for the jumps. Also, my scaling with the physics was off which meant my numbers were approaching/at the max value for some of the registers, so that was causing other issues.

I have a new one now though. You see that image, above?

All of those "WALL" tiles have square boxes assigned automatically, 64x64 pixels in size. I've got things set up so the boxes are aligned perfectly, each at the same Y coordinate and each exactly 64 pixels apart. However, when my "NINJA" box is speeding along the ground, it judders and sometimes gets knocked as if it has hit a small "bump".

The only explanation I can come up with is that the physics squares for the "WALL" tiles aren't lined up perfectly, or the physics isn't precise enough to do this. I've tried extending the boxes slightly so that they overlap by a pixel or two, but that doesn't seem to help.

Has anyone else had this problem, and have you any ideas on how to fix it?
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 18th Feb 2012 05:32 Edited at: 18th Feb 2012 05:32
I have the same problem. I haven't fixed it yet, but I was planning to by making the corner's of my sprite flared up so that when it hits a corner like so:



I don't know if it'll actually work, but that's the first thing I was gonna try. Let me know what you find.

Attachments

Login to view attachments
KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 19th Feb 2012 09:53
Nah, that will make the problem less pronounced but it shouldn't fix it - I tried setting my sprite to have a circular collision and it still jitters and bumps.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 19th Feb 2012 13:01
Does this happen on every tile? I can see a difference of about one pixel part way along your platform...?

Have you tried setting the sprite shape as polygon? I have found this to be more accurate even for rectangular or square sprites. Could be a bug there I guess?

bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 20th Feb 2012 11:35 Edited at: 20th Feb 2012 11:35
My tiles line up perfectly. I won't be able to test polygon collision for some time, but I'll post here when I get to it.

KareDev
12
Years of Service
User Offline
Joined: 6th Feb 2012
Location:
Posted: 21st Feb 2012 21:29
They're all set to the same Y coordinate as an integer value - if they're not lined up, then I don't think it's anything I've done.

I'm assuming at this point you get rounding errors or something?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 22nd Feb 2012 09:34
I'm not aware of any rounding errors to this extent.

Something that has occurred to me is that it could be down to friction... Try playing with the friction of your sprite (IE. set it to 0.0 or a very low value). Could be that the jitter is down to a none rotating sprite trying to deal with friction?

Login to post a reply

Server time is: 2024-05-02 01:36:07
Your offset time is: 2024-05-02 01:36:07