Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Physics bounciness and degrees of freedom not working? #2368

Closed
eonarheim opened this issue Jun 26, 2022 Discussed in #2365 · 0 comments · Fixed by #2369
Closed

Physics bounciness and degrees of freedom not working? #2368

eonarheim opened this issue Jun 26, 2022 Discussed in #2365 · 0 comments · Fixed by #2369

Comments

@eonarheim
Copy link
Member

Discussed in #2365

Originally posted by KokoDoko June 26, 2022
I am building a excalibur game with realistic physics, in my game I enable physics with

class Game {
  constructor(){
    Physics.useRealisticPhysics()
    Physics.gravity = new Vector(0, 800)
    this.engine = new Engine()
    // ...
  }
}

This works, and I can add Actors with physics properties, except for these two:

this.body.bounciness //and friction, mass, inertia
this.body.limitDegreeOfFreedom.push(DegreeOfFreedom.Rotation)

The body does not bounce, and can still rotate around the z axis. Am I missing something?
The whole class:

export class Mario extends Actor {

    constructor(texture) {
        super({ width: texture.width, height: texture.height }) // collision box size is working
        this.graphics.use(texture.toSprite())
        // enable physics
        this.body.useGravity = true // working
        this.body.collisionType = CollisionType.Active // working
        this.body.bounciness = 0.7 // not working
        this.body.limitDegreeOfFreedom.push(DegreeOfFreedom.Rotation) // not working

        // all the console logs are working
        console.log(this.body.mass)
        console.log(this.body.inertia)
        console.log(this.body.bounciness)
        console.log(this.body.friction)
        console.log(this.body)
   }
 }

BTW I am using the .esm version, I import excalibur as a native module from https://esm.sh/excalibur

eonarheim added a commit that referenced this issue Jun 27, 2022
Closes #2368

This PR corrects the math around elastic collisions in the realistic collision solver, elastic collisions now preserve energy as expected.

Additionally this PR also fixes an issue with the degrees of freedom limiter

![bouncy](https://user-images.githubusercontent.com/612071/175856506-17f3f6d5-d7af-4b1f-96d8-639205a04078.gif)
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant