Wrong direction of gravity

Wrong direction of gravity


I am currently making a projected trajectory with this tutorial: https://www.iforce2d.net/b2dtut/projected-trajectory
Using the same formula with the author, I made the projected trajectory but the direction of the gravity seems quite wrong, it heading to the bottom left of the screen like showing on this image:

My drawing code is like this:

getTrajectoryPoint: function(pos, velocity, n) {
    var t = 1/10;
    var stepGravY = t*t*cc.director.getPhysicsManager().gravity.y;
    return cc.p(pos.x + n*t*velocity.x + 0.5*(n*n + n)*stepGravY, pos.y + n*t*velocity.y + 0.5*(n*n + n)*stepGravY);


Hi, I haven’t seen that tutorial but if you’re doing a “Projectile motion” then the x component should not be affected by the gravity at all


Thanks it worked. Shame for me that’s some basic physics knowledge.


You can use cc.jump


but that cause jerks in ball the case he is dealing with.


@ginrex can you share any code snippet please. Also some more good resources.


Sorry I didn’t think someone could go back to this game lol, anyway sorry but I don’t have the project with me anymore. As far as I remember, the problem was that I tried to adjust the x-axis of the projected trajectory based on gravity, it was pointed out by zerodarkzone that it was just a fail in my formula lol.


thanks for response. okay i check it out.