Hey, i am creating game and I need some help. I know how to make script that will return x and y coordinates of the mouse/touchpad, but I dont know how to return weapon angle around player to crosshair.
OK, I've got it EXCEPT 1 thing I have to say: Mx = event.clientX; My = event.clientY; // x, y are pre-defined as player x and y s, offsets are predefined by the angle I aim and, gun size, etc. transX = x - Mx; transY = y - My var GunAimRadians = math.atan2(transX - Xoffset, transY - Yoffset) var Aim = GunAimRadians*180/Math.PI - 90. //-90 is VERY important or otherwise it will aim 90 deg up Then.... bullets, etc. You know, I have been experimenting with "Tululoo Game Maker"(uses pure JS, no frameworks such as JQuery) and I have found something interesting here: http://trickkr.com/item/67/rezoners-games-from-scratch-bullets
Comments
And angle should be returned in degrees too
angle = Math.atan2(x1-x0, y1-y0);
You just have to keep in mind that the y-axis point toward the bottom and the origine (0,0) is on the top-left corner of the window.
function RadToDeg(radians){
//converting radians to degrees
degrees = radians*(180/Math.PI);
return degrees;
}
function ReturnPlayerAimDegree(PlayerX,PlayerY,event){
//Everything's clear lets go
var PlayerCurrentMouseX = event.clientX;
var PlayerCurrentMouseY = event.clientY;
this.TransX = PlayerCurrentMouseX-PlayerX;
this.TransY = PlayerCurrentMouseY-PlayerY;
var RadDegPlayerOperation = Math.atan2(this.TransX,this.TransY);
document.getElementById("demo").innerHTML = RadToDeg(RadDegPlayerOperation);
return RadToDeg(RadDegPlayerOperation);
}
"
This script above works well
Thank you,
Everything's clear
Hope I will make aiming script correctly
Mx = event.clientX;
My = event.clientY;
// x, y are pre-defined as player x and y s, offsets are predefined by the angle I aim and, gun size, etc.
transX = x - Mx;
transY = y - My
var GunAimRadians = math.atan2(transX - Xoffset, transY - Yoffset)
var Aim = GunAimRadians*180/Math.PI - 90. //-90 is VERY important or otherwise it will aim 90 deg up
Then.... bullets, etc.
You know, I have been experimenting with "Tululoo Game Maker"(uses pure JS, no frameworks such as JQuery) and I have found something interesting here:
http://trickkr.com/item/67/rezoners-games-from-scratch-bullets