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 5995869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:01:21+00:00 2026-05-23T00:01:21+00:00

I am brand new to game development and I thought it would be fun

  • 0

I am brand new to game development and I thought it would be fun to try out Gosu, Ruby and Chipmunk together.
So far I have a player and a ball on a 2d Top-Down field and they collide.
My problem right now is that I want my player to be a square.
I sucked at Math in high school and that was way too many years ago to think about.
The documentation for Chipmunk says this about drawing a Polygon:

# Create a poly collision shape attached to the given body at
# the given offset with the given vertexes. _verts_ must be an
# Array of CP::Vect with a counterclockwise winding.
 def initialize(body, verts, offset); end

I have this code to get my polygon right now:

verts = Array.new
verts.push(CP::Vec2.new(0,32))
verts.push(CP::Vec2.new(32,32))
verts.push(CP::Vec2.new(32,0))
verts.push(CP::Vec2.new(0,0))

@shape = CP::Shape::Poly.new(@body, verts, CP::Vec2.new(0,0))

That ends up giving me a shape attached to my square png, but it appears as if 0,0 is the top, left corner of the image and the actual Polygon starts even farther to the top, left of the image.

So I assumed I should set the “Offset” to half of my width of my Polygon but that doesn’t give me the right outcome.

I am sure that for most people on here this is elementary. But I am still in the elementary when it comes to game dev.
Can someone explain this to me please?

EDIT
Here is my full code as of 5/28/2011

  • 1 1 Answer
  • 1 View
  • 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-05-23T00:01:22+00:00Added an answer on May 23, 2026 at 12:01 am

    Looks like your problems stem from inconsistencies between drawing and collision origins.

    In effect, your ball is drawn centered on x,y, while the player is drawn with top left corner on x,y. That coupled with your Player shape not being centered on x,y is causing you difficulties.

    To center the drawing of your player, just use the draw_rot method with an angle of 0 to avoid rotating the image.

    class Player
      def draw
        @image.draw_rot(@shape.body.pos.x, @shape.body.pos.y, 1, 0, 0.5, 0.5, 1, 1)
      end
    end
    

    To make the Chipmunk shape fit the centered player image, you need to offset your vertices by half the size of the shape. You can hardcode this doing

    class Player
      def initialize(space, image) 
        ...
        verts = Array.new
        verts.push(CP::Vec2.new(-16,16))
        verts.push(CP::Vec2.new(16,16))
        verts.push(CP::Vec2.new(16,-16))
        verts.push(CP::Vec2.new(-16,16))
        ...
      end
    end
    

    or simply do it at runtime with

    CP::recenter_poly(verts)
    

    before you add verts to your shape.

    With those changes in place I suspect your physics will behave more like you expect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Brand new to Cocoa and I'm trying to figure out how to copy an
I'm brand new to SQL Server 2008, and have some newbie questions about the
Brand new to android and facing a weird problem.Check out the code below FirstActivity.java:
new to java and brand new to the site. I have a JLabel added
I am brand new to joomla, and am trying to have a few sections,
I am a brand new Java developer (I have been working in asp.net) and
Brand new to Ruby. Am trying to sort a de-duplicated list of email FROM
Am brand new to Ruby looking to get Redmine to run on WinServer08 sp1
First I'm brand new to JS but have an idea that object classes are
I'm brand new to ruby. I've written a little script, and at the top

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.