Ich bin ziemlich neu in JavaScript und ich habe versucht, ein kleines Spiel aufzubauen, um neue Konzepte zu lernen. Ein Problem, auf das ich begegnet bin, ist, dass Projektile im Spiel oft eine höhere Geschwindigkeit haben als die Breite der Objekte, mit denen sie kollidieren sollten, und so durch die Kollision auf den Kollision in jedem Rahmen vorbeikommen. Mein aktueller Code nimmt ein Rechteck und einen Kreis zusammen, zusammen mit ihren x jeder Y -Geschwindigkeit und erhält ihre relative Geschwindigkeit. Es wird dann den Bereich des Rechtecks im x und y um das 2 -fache des Radius des Kreises aufblasen.
function sweptAABB(pointx, pointy, velx, vely, deltaTime, rectx, recty, rectw, recth){
//pointx and pointy are the circle's center, velx and vely are the relative velocities
//how far the "point" (this is the circle, but it's a point since we're expanding our rectangle to account for it's radius) will move during the frame:
const movementX = velx*(deltaTime);
const movementY = vely*(deltaTime)
const invMoveX = movementX !== 0 ? 1 / movementX : Infinity;
const invMoveY = movementY !== 0 ? 1 / movementY : Infinity;
//times that the point would enter/exit the rectangle
const tEnterXY = {x: (rectx-pointx)*invMoveX, y:(recty - pointy) * invMoveY}
const tExitXY = {x: (rectx+rectw-pointx)*invMoveX, y:(recty+recth - pointy) * invMoveY};
//the earliest posible enter/exit times
const enterTime = Math.max(Math.min(tEnterXY.x, tExitXY.x), Math.min(tEnterXY.y, tExitXY.y));
const exitTime = Math.min(Math.max(tEnterXY.x, tExitXY.x), Math.max(tEnterXY.y, tExitXY.y));
return enterTime = 0 && enterTime
Ich bin ziemlich neu in JavaScript und ich habe versucht, ein kleines Spiel aufzubauen, um neue Konzepte zu lernen. Ein Problem, auf das ich begegnet bin, ist, dass Projektile im Spiel oft eine höhere Geschwindigkeit haben als die Breite der Objekte, mit denen sie kollidieren sollten, und so durch die Kollision auf den Kollision in jedem Rahmen vorbeikommen. Mein aktueller Code nimmt ein Rechteck und einen Kreis zusammen, zusammen mit ihren x jeder Y -Geschwindigkeit und erhält ihre relative Geschwindigkeit. Es wird dann den Bereich des Rechtecks im x und y um das 2 -fache des Radius des Kreises aufblasen.[code]function sweptAABB(pointx, pointy, velx, vely, deltaTime, rectx, recty, rectw, recth){ //pointx and pointy are the circle's center, velx and vely are the relative velocities
//how far the "point" (this is the circle, but it's a point since we're expanding our rectangle to account for it's radius) will move during the frame: const movementX = velx*(deltaTime); const movementY = vely*(deltaTime)
Ich versuche, zwei Rechtecke als Hindernis und ein Finish zu erstellen. Das Player -Rechteck ist Square_Pos, das Hindernisrechteck ist wall_pos und das Finish -Rechteck ist digiN_pos.
import...
Ich habe ein Projekt in Flask in Blaupausen für jede App aufgeteilt. Ich möchte die Vorlage jedes Blaupauses schrittweise in React umschreiben, aber ich muss alle in einem React -Projekt sein....
Ich habe 2 Punkte auf einem Kreis und den Winkel zwischen ihnen und ich möchte die so definierte Mitte des Kreises finden (gut, beide Zentren vorzugsweise). Hier src = />