I have been trying recently to add a feature to my 2D game where I can make the player dash forwards when they press SPACE. Does anyone know how I would make angular force such as: apply force “10” at “facing angle of player”
The above situation in Italics is an example of my end goal. Does anyone know what I would need to do (IN p2.js) in order to apply a force at the facing angle of my 2D player
Thanks,
Chhes
[SOLUTION]:
In order to solve this I used some of the code below, but instead of using this.entity.forward I used this.entity.up only for the x and y axis.
Hello again @Leonidas it seems that the angular force I implemented did not work. I do not think that body.angularForce is actually an array so it did not work. Here is what I put:
When I logged the values for angularForce[0] and [1] they would show as 100 since I am testing with that first. The player does not move whatsoever when I pressed or even held down space. Any other ideas?
honestly, once ANY form of launching my character works (e.g. impulse, force) then I will be able to customize it, I am just not sure how to get the player to launch at its facing angle since none of the methods I have tried are actually… launching it
Hey Thanks for the help so far, but I am having trouble with applyImpulse() since it is not actually sending my player in any distance at any angle anywhere. I have been trying to figure this out but cannot seem to get it right. Do you happen to know why the applyImpulse() may not be working correctly?
if (this.app.keyboard.wasPressed(pc.KEY_SPACE)) {
this.entity.script.p2Body.body.applyImpulse([10, 10]);
}
Another thing is that my this.entity.forward.x or .y was equal 0 and the .z was equal to -1, so I removed it for now in order to test this current issue.