Apply scaling to NPC collider dimensions (capsule and box)
This commit is contained in:
@@ -1084,6 +1084,10 @@ export function buildRuntimeNpcCollider(
|
|||||||
|
|
||||||
switch (npc.collider.mode) {
|
switch (npc.collider.mode) {
|
||||||
case "capsule": {
|
case "capsule": {
|
||||||
|
const radius = npc.collider.radius * Math.max(npc.scale.x, npc.scale.z);
|
||||||
|
const height = npc.collider.height * npc.scale.y;
|
||||||
|
const eyeHeight = npc.collider.eyeHeight * npc.scale.y;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
kind: "character",
|
kind: "character",
|
||||||
source: "npc",
|
source: "npc",
|
||||||
@@ -1092,29 +1096,34 @@ export function buildRuntimeNpcCollider(
|
|||||||
rotationDegrees,
|
rotationDegrees,
|
||||||
shape: {
|
shape: {
|
||||||
mode: "capsule",
|
mode: "capsule",
|
||||||
radius: npc.collider.radius,
|
radius,
|
||||||
height: npc.collider.height,
|
height,
|
||||||
eyeHeight: npc.collider.eyeHeight
|
eyeHeight
|
||||||
},
|
},
|
||||||
worldBounds: {
|
worldBounds: {
|
||||||
min: {
|
min: {
|
||||||
x: npc.position.x - npc.collider.radius,
|
x: npc.position.x - radius,
|
||||||
y: npc.position.y,
|
y: npc.position.y,
|
||||||
z: npc.position.z - npc.collider.radius
|
z: npc.position.z - radius
|
||||||
},
|
},
|
||||||
max: {
|
max: {
|
||||||
x: npc.position.x + npc.collider.radius,
|
x: npc.position.x + radius,
|
||||||
y: npc.position.y + npc.collider.height,
|
y: npc.position.y + height,
|
||||||
z: npc.position.z + npc.collider.radius
|
z: npc.position.z + radius
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case "box": {
|
case "box": {
|
||||||
|
const size = {
|
||||||
|
x: npc.collider.size.x * npc.scale.x,
|
||||||
|
y: npc.collider.size.y * npc.scale.y,
|
||||||
|
z: npc.collider.size.z * npc.scale.z
|
||||||
|
};
|
||||||
const halfExtents = {
|
const halfExtents = {
|
||||||
x: npc.collider.size.x * 0.5,
|
x: size.x * 0.5,
|
||||||
y: npc.collider.size.y * 0.5,
|
y: size.y * 0.5,
|
||||||
z: npc.collider.size.z * 0.5
|
z: size.z * 0.5
|
||||||
};
|
};
|
||||||
const yawRadians = (rotationDegrees.y * Math.PI) / 180;
|
const yawRadians = (rotationDegrees.y * Math.PI) / 180;
|
||||||
const cosine = Math.abs(Math.cos(yawRadians));
|
const cosine = Math.abs(Math.cos(yawRadians));
|
||||||
@@ -1130,8 +1139,8 @@ export function buildRuntimeNpcCollider(
|
|||||||
rotationDegrees,
|
rotationDegrees,
|
||||||
shape: {
|
shape: {
|
||||||
mode: "box",
|
mode: "box",
|
||||||
size: cloneVec3(npc.collider.size),
|
size,
|
||||||
eyeHeight: npc.collider.eyeHeight
|
eyeHeight: npc.collider.eyeHeight * npc.scale.y
|
||||||
},
|
},
|
||||||
worldBounds: {
|
worldBounds: {
|
||||||
min: {
|
min: {
|
||||||
@@ -1141,7 +1150,7 @@ export function buildRuntimeNpcCollider(
|
|||||||
},
|
},
|
||||||
max: {
|
max: {
|
||||||
x: npc.position.x + rotatedHalfX,
|
x: npc.position.x + rotatedHalfX,
|
||||||
y: npc.position.y + npc.collider.size.y,
|
y: npc.position.y + size.y,
|
||||||
z: npc.position.z + rotatedHalfZ
|
z: npc.position.z + rotatedHalfZ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user