Coder Social home page Coder Social logo

Comments (8)

aismann avatar aismann commented on June 1, 2024

Use friction on the body/shape

from chipmunk2d.

VictorQueiroz avatar VictorQueiroz commented on June 1, 2024

@aismann if you mean to set friction on the player's body shape, I tried that, but it didn't have any effect. I am using cpBodyApplyImpulseAtLocalPoint to apply the impulse and make the player move, am I doing it wrong?

from chipmunk2d.

aismann avatar aismann commented on June 1, 2024

Let me See the source snippet plz
or look on the manual:

cpFloat cpShapeGetFriction(const cpShape *shape)
void cpShapeSetFriction(cpShape *shape, cpFloat value)

Friction coefficient. Chipmunk uses the Coulomb friction model, a value of 0.0 is frictionless. The friction for a collision is found by multiplying the friction of the individual shapes together. Tables of friction coefficients.

from chipmunk2d.

VictorQueiroz avatar VictorQueiroz commented on June 1, 2024

@aismann I pushed my testing application here so you can check:

https://github.com/VictorQueiroz/Chipmunk2D-TopDown-Test

from chipmunk2d.

aismann avatar aismann commented on June 1, 2024

@VictorQueiroz
I think cpShapeSetFriction() is only working sliding on other shapes. My mistake.

from chipmunk2d.

VictorQueiroz avatar VictorQueiroz commented on June 1, 2024

@aismann what is the alternative to achieve what I want?

from chipmunk2d.

VictorQueiroz avatar VictorQueiroz commented on June 1, 2024

@aismann here is the video you asked:

2022-12-29 15-55-56.zip

from chipmunk2d.

VictorQueiroz avatar VictorQueiroz commented on June 1, 2024

I finally made it. I updated the project I sent you on GitHub. A comment from a guy in Reddit helped me fix it:

I can't read c++ very well, but from what you describe it sounds like you haven't implemented drag yet. I like to implement it like this:

velocity = velocity - (velocity * 0.25 * time.deltaTime)

Velocity in this case is the movement vector of your object. You just lower it by a percentage per second until the movement is so little that it's basically stopped. However, it is good to note that it will never actually stop like this.

You could implement drag a different way, it's really up to your preference.

I gently set it's velocity on every frame:

cpVect vel = cpBodyGetVelocity(body.playable->controlBody);
vel = vel - (vel * 0.25 * dt);
cpBodySetVelocity(body.playable->controlBody, vel);

from chipmunk2d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.