Skip to content

Commit

Permalink
Merge pull request #21 from Crazy-Cow/CD-68
Browse files Browse the repository at this point in the history
Feature: reset position
  • Loading branch information
seven05 authored Nov 15, 2024
2 parents 889da47 + 327a31d commit a7f92f9
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/app_cannon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ const handleCatch = (character: Character) => {
}
}
}
// 캐릭터 위치 초기화 함수
const resetPosition = (character: Character) => {
const newPosition = generateRandomPosition()
if (character.cannonBody) {
character.cannonBody.position.set(
newPosition.x,
newPosition.y,
newPosition.z
)
character.cannonBody.velocity.set(0, 0, 0) // 속도도 초기화
character.cannonBody.angularVelocity.set(0, 0, 0) // 각속도 초기화
}
character.position = newPosition
character.velocity = { x: 0, y: 0, z: 0 }
character.isOnGround = true
console.log(`Character ${character.id} reset to initial position.`)
}

// 필요한 데이터를 캐릭터 목록으로 변환하는 함수
function getSerializableCharacters(raw_characters: Character[]) {
Expand Down Expand Up @@ -250,10 +267,14 @@ setInterval(() => {

characters.forEach((character) => {
character.isBeingStolen = false
console.log(character.id, character.position)
})

characters.forEach((character) => {
// console.log(character.id, character.position)
if (
Math.abs(character.position.x) > 30 ||
Math.abs(character.position.y) > 30 ||
Math.abs(character.position.z) > 30
) {
resetPosition(character)
}
if (character.cannonBody) {
character.position = {
x: character.cannonBody.position.x,
Expand Down

0 comments on commit a7f92f9

Please sign in to comment.