This commit is contained in:
Schmelczer András 2020-10-11 20:32:56 +02:00
commit cd75bdbfde
3 changed files with 252 additions and 130 deletions

View file

@ -44,19 +44,22 @@ export class CharacterPhysical extends CharacterBase implements Physical {
constructor(private readonly container: PhysicalContainer) {
super(id());
this.head = new CirclePhysical(
vec2.clone(CharacterPhysical.headOffset),
//vec2.clone(CharacterPhysical.headOffset),
[-2952.911, 215.241],
50,
this,
container,
);
this.leftFoot = new CirclePhysical(
vec2.clone(CharacterPhysical.leftFootOffset),
// vec2.clone(CharacterPhysical.leftFootOffset),
[-2930.603, 162.542],
20,
this,
container,
);
this.rightFoot = new CirclePhysical(
vec2.clone(CharacterPhysical.rightFootOffset),
//vec2.clone(CharacterPhysical.rightFootOffset),
[-2973.152, 167.921],
20,
this,
container,

View file

@ -136,12 +136,6 @@ export class CirclePhysical implements Circle, Physical {
if (hitSurface) {
vec2.scale(this.velocity, tangent!, vec2.dot(tangent!, this.velocity));
if (
vec2.length(this.velocity) <
settings.frictionMinVelocity * deltaTimeInSeconds
) {
this.velocity = vec2.create();
}
wasHit = true;
}
}

View file

@ -0,0 +1,61 @@
import { vec2 } from 'gl-matrix';
import {
id,
StepCommand,
settings,
CommandExecutors,
serializesTo,
ProjectileBase,
} from 'shared';
import { ImmutableBoundingBox } from '../physics/bounding-boxes/immutable-bounding-box';
import { CirclePhysical } from './circle-physical';
import { Physical } from '../physics/physical';
import { PhysicalContainer } from '../physics/containers/physical-container';
@serializesTo(ProjectileBase)
export class ProjectilePhysical extends ProjectileBase implements Physical {
public readonly canCollide = true;
public readonly isInverted = false;
public readonly canMove = true;
public object: CirclePhysical;
protected commandExecutors: CommandExecutors = {
[StepCommand.type]: this.step.bind(this),
};
constructor(
center: vec2,
radius: number,
startingForce: vec2,
readonly container: PhysicalContainer,
) {
super(id(), center, radius);
this.object = new CirclePhysical(center, radius, this, container);
this.object.applyForce(startingForce, 1000);
}
private _boundingBox?: ImmutableBoundingBox;
public get boundingBox(): ImmutableBoundingBox {
if (!this._boundingBox) {
this._boundingBox = (this.object as CirclePhysical).boundingBox;
}
return this._boundingBox;
}
public get gameObject(): this {
return this;
}
public distance(target: vec2): number {
return this.object.distance(target);
}
public step(c: StepCommand) {
const deltaTime = c.deltaTimeInMiliseconds / 1000;
this.object.applyForce(settings.gravitationalForce, deltaTime);
this.object.step(deltaTime);
}
}