Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7724929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:48:44+00:00 2026-06-01T04:48:44+00:00

I have a character (whose (x, y) position is stored in bodyc), and a

  • 0

I have a character (whose (x, y) position is stored in bodyc), and a bunch of platforms. These platforms are represented in a variable “plist”, and are stored in the fashion [[x, y], pygame.Surface instance]. The character jumps with velocity.

This is my current algorithm:

def onplatform(self):
    for i in plist:
        if intersect(i[0]+list(i[1].get_size()), [bodyc[0], bodyc[1], 50, 50]):
            return True, plist.index(i)
        return False, len(plist)

onplat=self.onplatform()
if yvelocity!=-13:
    bodyc[1]-=yvelocity
if yvelocity>-12: yvelocity-=1
if yvelocity==-13 and not onplat[0]: yvelocity=-1
if onplat[0] and -13<yvelocity<-1:
    yvelocity=-13
    bodyc[1]=plist[onplat[1]][0][1]-50 #(y-value of platform)-50
if pressed[pygame.K_UP] and yvelocity==-13:
    yvelocity=13

The problem with this algorithm is that when the character is touching the platform, even if the bottom is not on the platform, the code will put the character onto the platform anyways.

I’ve tried making it so the hitbox is very small (1 or 3 pixels high), but the character doesn’t touch the platform at all, because the velocity makes the character skip over the platform. Setting it bigger, like 5 or 7 pixels, has the same problem as described above.

Is there an easy way of fixing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:48:46+00:00Added an answer on June 1, 2026 at 4:48 am

    I found out the answer (it actually took about 20 minutes to do it).

    prevcoords are the previous coordinates of bodyc, the coordinates of the sprite, yvelocity is the y-velocity of the character.

    For future programmers who are also stuck with the “platforming problem”: You’ll have to modify this program if you want to make a multi-screen platformer, because this is really inefficient. Also, this may not work with asymmetric sprites.

    def intersect(recta, rectb):
        a=(rectb[1]+rectb[3]<recta[1]) or (recta[1]+recta[3]<rectb[1]) #up, down
        b=(rectb[0]+rectb[2]<recta[0]) or (recta[0]+recta[2]<rectb[0]) #left, right
    return not(a or b)
    
    def onplatform(self):
        for i in plist:
            if intersect(i[0]+[i[1].get_width(), 1], [bodyc[0], bodyc[1]+47, 50, 3]):
                return True, plist.index(i)
    
    onplat=self.onplatform()
    if yvelocity!=-13:
        bodyc[1]-=yvelocity
        for i in plist:
            temp=i[0][0]<bodyc[0]+50<i[0][0]+i[1].get_width()
            temp2=i[0][0]<bodyc[0]<i[0][0]+i[1].get_width()
            if prevcoords[1]+50<=i[0][1]<=bodyc[1]+50 and (temp or temp2):
                bodyc[1]=i[0][1]-50
                yvelocity=-13
                break
    if yvelocity>-12: yvelocity-=1
    if yvelocity==-13 and not onplat[0]: yvelocity=-1
    if pressed[pygame.K_UP] and yvelocity==-13:
        yvelocity=13
    prevcoords=bodyc[:]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In SAS/IML I have defined a character variable: var1 = usernames; Previously in the
I have a column in my oracle db as character and data stored in
I have a menu link whose link title contains a character entity (e.g. La
I have a character array and I'm trying to figure out if it matches
i have a character controller which jumps but while jumping i want to change
They're both resizable arrays, and std::basic_string doesn't have any specifically character-related functions like upper().
I have a single hexadecimal character, say char c = 'A'; What's the proper
I have several 450 element character arrays (storing bitmap data to display on lcd
I have an html special character I want to toggle off and on like
I have previously read Spolsky's article on character-encoding, as well as this from dive

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.