2d Trig Question
in
Contributed Library Questions
•
2 years ago
- int playerx = 400;
int playery = 300;
void mousePressed() {
float xforce =mouseX-playerx? //these two need to be converted to between -0.5 & 0.5
float yforce =mouseY-playerY?
bullets.add(new Bullet(playerx, playery, xforce*gunSpeed, yforce*gunSpeed));
}
class Bullet {
Body b;
Bullet(int x_, int y_, float xF_, float yF_) {
b = new FBody();
b.setPosition(x_, y_);
b.applyForce(xF_, yF);
world.add(b);
}
}
The code is just off the top of my head since I am not at home, but it is very simple. The FBody reference is just the physics engine Fisica I am calling and is just there for clarifying my problem. I may be altogether doing this the wrong way. What my issue was before was that if my mouse was close to the body the bullet would not have strength to move and if it was at an edge it would zoom past. I need it to be a consistant amount of power added to the bullet. This has been stumping me for over a week, I think I could solve it with trig but not sure of the route? Thanks
1