Fix some issues

This commit is contained in:
schmelczerandras 2020-11-03 23:40:14 +01:00
commit 1ce961d6c2
2 changed files with 428 additions and 196 deletions

View file

@ -1,24 +0,0 @@
import { vec2 } from 'gl-matrix';
import { Circle } from 'shared';
import { CirclePhysical } from '../../objects/circle-physical';
export const applySpringForce = (
a: CirclePhysical | Circle,
b: CirclePhysical | Circle,
distance: number,
strength: number,
deltaTimeInSeconds: number,
) => {
const length = vec2.dist(a.center, b.center) - distance;
const abDirection = vec2.subtract(vec2.create(), b.center, a.center);
vec2.normalize(abDirection, abDirection);
const force = vec2.scale(abDirection, abDirection, strength * length);
if (a instanceof CirclePhysical) {
a.applyForce(force, deltaTimeInSeconds);
}
if (b instanceof CirclePhysical) {
vec2.scale(force, force, -1);
b.applyForce(force, deltaTimeInSeconds);
}
};

View file

@ -17,7 +17,12 @@ export const moveCircle = (
tangent?: vec2;
hitObject?: GameObject;
} => {
const direction = vec2.normalize(vec2.create(), delta);
const direction = vec2.clone(delta);
if (vec2.length(delta) > 0) {
vec2.normalize(direction, direction);
}
const deltaLength = vec2.length(delta);
let travelled = 0;
let rayEnd = vec2.create();