#My "player" wont move by its velocity even though my code worked not long ago

8 messages · Page 1 of 1 (latest)

blissful sparrow
#

I'm using Vector2d to represent location, velocity, and acceleration, and accel changes vel and vel changes position, but the code that's meant to change position by velocity doesn't seem to be working.
problematic method below, full class in another message as well as github link

public static void physics() {
        players.forEach(p -> {
            p.stopYMomentum = false;
            p.limitVel();
            p.lastPos = new Vector2d(p.currPos);
            p.currPos = p.currPos.add(p.vel); // TODO - THIS LINE DOESNT WORK
            p.vel.add(p.acc);
            p.acc.y = ((p.acc.y - p.gravC) * 0.85) + p.gravC; // normalize vertical acceleration towards gravC
            p.acc.x *= 0.95; // normalize horizontal acceleration to zero
            p.vel.mul(0.99f);
            boundaries();
        });
    }
bitter flaxBOT
#

This post has been reserved for your question.

Hey @blissful sparrow! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

blissful sparrow
placid stag
#

You should update the position after updating acceleration and velocity

bitter flaxBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

blissful sparrow
#

changing certain bits of code outside the method somehow fixes and breaks it