Skip to content

Commit c188d60

Browse files
author
Your Name
committed
apply deltatime to speed in charactermovement
1 parent 4e3c2bd commit c188d60

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

Parts/CharacterMovement.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class CharacterMovement extends Part {
1616
this.type = "CharacterMovement";
1717
}
1818

19-
act(_delta: number): void {
19+
act(delta: number): void {
2020
if (!this.input) {
2121
if (!this.warned.has("MissingInput")) this.top?.warn(`CharacterMovement <${this.name}> (${this.id}) is missing an input property. Please create an input on the scene and pass it.`) ? this.warned.add("MissingInput") : null;
2222
return;
@@ -26,7 +26,7 @@ export class CharacterMovement extends Part {
2626
if (!transform) {
2727
return;
2828
}
29-
29+
const speed = this.speed * delta;
3030
const keys = this.input.downkeys;
3131
let dx = 0;
3232
let dy = 0;
@@ -66,7 +66,7 @@ export class CharacterMovement extends Part {
6666
dy *= Math.SQRT1_2;
6767
}
6868
if (dx !== 0 || dy !== 0) {
69-
transform.move(new Vector(dx * this.speed, dy * this.speed));
69+
transform.move(new Vector(dx * speed, dy * speed));
7070
}
7171
}
7272
}

Parts/Children/Collider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Vector } from "../../Math/Vector";
22
import type { Camera } from "../Camera";
33
import { Game } from "../Game";
44
import { Part } from "../Part";
5+
import type { Layer } from "../Layer";
56
import { MultiPolygonCollider } from "./MultiPolygonCollider";
67
import type { Transform } from "./Transform";
78
import * as martinez from 'martinez-polygon-clipping';
@@ -212,7 +213,7 @@ export abstract class Collider extends Part {
212213
this.collidingWith.clear();
213214

214215

215-
const layer = this.registrations.layer as import("../Layer").Layer;
216+
const layer = this.registrations.layer as Layer;
216217
const candidates = layer.spatialGrid.query(this);
217218

218219
for (const other of candidates) {

Parts/Layer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class Layer extends Part {
1212
this.type = "Layer";
1313
this.id = generateUID();
1414
this.debugEmoji = "🗂️"; // Default emoji for debugging the layer
15-
this.spatialGrid = new SpatialGrid(100);
15+
this.spatialGrid = new SpatialGrid(50);
1616
}
1717

1818
addChild(part: Part) {

engine/bundle.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11299,7 +11299,7 @@ class Layer extends Part {
1129911299
this.type = "Layer";
1130011300
this.id = generateUID();
1130111301
this.debugEmoji = "\uD83D\uDDC2️";
11302-
this.spatialGrid = new SpatialGrid(100);
11302+
this.spatialGrid = new SpatialGrid(50);
1130311303
}
1130411304
addChild(part) {
1130511305
part.setAll("layer", this);
@@ -13570,7 +13570,7 @@ class CharacterMovement extends Part {
1357013570
this.input = input;
1357113571
this.type = "CharacterMovement";
1357213572
}
13573-
act(_delta) {
13573+
act(delta) {
1357413574
if (!this.input) {
1357513575
if (!this.warned.has("MissingInput"))
1357613576
this.top?.warn(`CharacterMovement <${this.name}> (${this.id}) is missing an input property. Please create an input on the scene and pass it.`) && this.warned.add("MissingInput");
@@ -13580,6 +13580,7 @@ class CharacterMovement extends Part {
1358013580
if (!transform) {
1358113581
return;
1358213582
}
13583+
const speed = this.speed * delta;
1358313584
const keys = this.input.downkeys;
1358413585
let dx = 0;
1358513586
let dy = 0;
@@ -13616,7 +13617,7 @@ class CharacterMovement extends Part {
1361613617
dy *= Math.SQRT1_2;
1361713618
}
1361813619
if (dx !== 0 || dy !== 0) {
13619-
transform.move(new Vector(dx * this.speed, dy * this.speed));
13620+
transform.move(new Vector(dx * speed, dy * speed));
1362013621
}
1362113622
}
1362213623
}

engine/editor.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24333,7 +24333,7 @@ Defaulting to 2020, but this will stop working in the future.`);
2433324333
this.type = "Layer";
2433424334
this.id = generateUID();
2433524335
this.debugEmoji = "\uD83D\uDDC2️";
24336-
this.spatialGrid = new SpatialGrid(100);
24336+
this.spatialGrid = new SpatialGrid(50);
2433724337
}
2433824338
addChild(part) {
2433924339
part.setAll("layer", this);
@@ -26484,7 +26484,7 @@ Defaulting to 2020, but this will stop working in the future.`);
2648426484
this.input = input;
2648526485
this.type = "CharacterMovement";
2648626486
}
26487-
act(_delta) {
26487+
act(delta) {
2648826488
if (!this.input) {
2648926489
if (!this.warned.has("MissingInput"))
2649026490
this.top?.warn(`CharacterMovement <${this.name}> (${this.id}) is missing an input property. Please create an input on the scene and pass it.`) && this.warned.add("MissingInput");
@@ -26494,6 +26494,7 @@ Defaulting to 2020, but this will stop working in the future.`);
2649426494
if (!transform) {
2649526495
return;
2649626496
}
26497+
const speed = this.speed * delta;
2649726498
const keys = this.input.downkeys;
2649826499
let dx = 0;
2649926500
let dy = 0;
@@ -26530,7 +26531,7 @@ Defaulting to 2020, but this will stop working in the future.`);
2653026531
dy *= Math.SQRT1_2;
2653126532
}
2653226533
if (dx !== 0 || dy !== 0) {
26533-
transform.move(new Vector(dx * this.speed, dy * this.speed));
26534+
transform.move(new Vector(dx * speed, dy * speed));
2653426535
}
2653526536
}
2653626537
};

src/TestColliderMerge.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ game.addChild(s1);
2828

2929

3030
// Missing borders
31-
for (let x = 0; x < 5; x++) {
32-
for (let y = 0; y < 5; y++) {
31+
for (let x = 0; x < 59; x++) {
32+
for (let y = 0; y < 59; y++) {
3333
if ((x == 0 || y === 0) && Math.random() > 0.2) continue;
3434
const testObject = new GameObject({
3535
name: `Test Object (${x + 1}, ${y + 1})`
3636
});
3737

3838
const testTransform = new Transform({
39-
position: new Vector(30+x * 50, 500 + y * 50),
39+
position: new Vector(30+x * 80, 500 + y * 80),
4040
rotation: 0,
4141
scale: Vector.From(1)
4242
});
4343
const boxCollider = new BoxCollider({
44-
width: 50,
45-
height: 50,
44+
width: 80,
45+
height: 80,
4646
tag: "testObjects",
4747
});
4848
const colorRender = new ColorRender({

testDist/TestColliderMerge.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5929,7 +5929,7 @@ class Layer extends Part {
59295929
this.type = "Layer";
59305930
this.id = generateUID();
59315931
this.debugEmoji = "\uD83D\uDDC2️";
5932-
this.spatialGrid = new SpatialGrid(100);
5932+
this.spatialGrid = new SpatialGrid(50);
59335933
}
59345934
addChild(part) {
59355935
part.setAll("layer", this);
@@ -7624,7 +7624,7 @@ class CharacterMovement extends Part {
76247624
this.input = input;
76257625
this.type = "CharacterMovement";
76267626
}
7627-
act(_delta) {
7627+
act(delta) {
76287628
if (!this.input) {
76297629
if (!this.warned.has("MissingInput"))
76307630
this.top?.warn(`CharacterMovement <${this.name}> (${this.id}) is missing an input property. Please create an input on the scene and pass it.`) && this.warned.add("MissingInput");
@@ -7634,6 +7634,7 @@ class CharacterMovement extends Part {
76347634
if (!transform) {
76357635
return;
76367636
}
7637+
const speed = this.speed * delta;
76377638
const keys = this.input.downkeys;
76387639
let dx = 0;
76397640
let dy = 0;
@@ -7670,7 +7671,7 @@ class CharacterMovement extends Part {
76707671
dy *= Math.SQRT1_2;
76717672
}
76727673
if (dx !== 0 || dy !== 0) {
7673-
transform.move(new Vector(dx * this.speed, dy * this.speed));
7674+
transform.move(new Vector(dx * speed, dy * speed));
76747675
}
76757676
}
76767677
}
@@ -26632,21 +26633,21 @@ var l1 = new Layer({
2663226633
});
2663326634
s1.addChild(l1);
2663426635
game.addChild(s1);
26635-
for (let x = 0;x < 5; x++) {
26636-
for (let y = 0;y < 5; y++) {
26636+
for (let x = 0;x < 59; x++) {
26637+
for (let y = 0;y < 59; y++) {
2663726638
if ((x == 0 || y === 0) && Math.random() > 0.2)
2663826639
continue;
2663926640
const testObject = new GameObject({
2664026641
name: `Test Object (${x + 1}, ${y + 1})`
2664126642
});
2664226643
const testTransform = new Transform({
26643-
position: new Vector(30 + x * 50, 500 + y * 50),
26644+
position: new Vector(30 + x * 80, 500 + y * 80),
2664426645
rotation: 0,
2664526646
scale: Vector.From(1)
2664626647
});
2664726648
const boxCollider = new BoxCollider({
26648-
width: 50,
26649-
height: 50,
26649+
width: 80,
26650+
height: 80,
2665026651
tag: "testObjects"
2665126652
});
2665226653
const colorRender = new ColorRender({

0 commit comments

Comments
 (0)