Skip to content

Nothing Moves #17

Description

@dragonfax

I followed the instructions for the hello world program, in the PDF linked from the README. And nothing moves. Perhaps I did something wrong.

func main() {

	var gravity = d2.MakeB2Vec2(0.0, -10.0)
	var world = d2.MakeB2World(gravity)

	groundBodyDef := d2.B2BodyDef{}
	groundBodyDef.Position.Set(0, -10)
	groundBody := world.CreateBody(&groundBodyDef)
	groundBox := d2.B2PolygonShape{}
	groundBox.SetAsBox(50, 10)
	groundBody.CreateFixture(&groundBox, 0)

	bodyDef := d2.B2BodyDef{}
	bodyDef.Type = d2.B2BodyType.B2_dynamicBody
	bodyDef.Position.Set(0, 4)
	body := world.CreateBody(&bodyDef)
	dynamicBox := d2.B2PolygonShape{}
	dynamicBox.SetAsBox(1, 1)
	fixtureDef := d2.B2FixtureDef{}
	fixtureDef.Shape = &dynamicBox
	fixtureDef.Density = 1
	fixtureDef.Friction = 0.3
	body.CreateFixtureFromDef(&fixtureDef)

	timeStep := 1.0 / 60.0
	velocityIterations := 6
	positionIterations := 2

	for i := 0; i < 60; i++ {
		world.Step(timeStep, velocityIterations, positionIterations)
		position := body.GetPosition()
		angle := body.GetAngle()
		fmt.Printf("%4.2f %4.2f %4.2f\n", position.X, position.Y, angle)
	}
}
$ go run main.go 
0.00 4.00 0.00
0.00 4.00 0.00
0.00 4.00 0.00
0.00 4.00 0.00
0.00 4.00 0.00
0.00 4.00 0.00
...

Truthfully I tried incorporating this module into another project I'm working on and it failed there. Which is when I took a step back, tried the hello world, and found that didn't work either.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions