#Facing 180° Angle

1 messages · Page 1 of 1 (latest)

glacial lark
#

I need my block to spawn projectile in which it faces, which varies the number of projectile summoned to a 180° relative to its facing direction. I use .applyImpulse() to my entity and i dont know how to relate the xyz to the block face.

#

this post was made using microsoft word

long bough
#

how are you determining the block face?

glacial lark
#
world.beforeEvents.playerInteractWithBlock.subscribe((e) => {
  if (e.block.typeId !== "trap:dispenser") return;
  let blockLocation = e.block.location;
  blockLocation.x += 0.5; //to offset middle of the block
  blockLocation.z += 0.5; //to offset middle of the block
  var num = 5 //number of projectiles

  for (let i = 0; i < num; i++) {
    let projectile = e.block.dimension.spawnEntity('trap:arrow',blockLocation)
    //idk what to do anymore
    projectile.applyImpulse({ x: ??, y: 0.5, z: ??})
  }
}
)
long bough
#

do you have a bundler setup to use external packages or are you just using plain scripts?

glacial lark
glacial lark
#

im very bad at these maths

long bough
#

there's that post that shows how to use a bundler

#

as for what package I recommend using for math, @bedrock-oss/bedrock-boost

glacial lark
glacial lark
#

yawqna

glacial lark
#

still need help with diz

solid shadow
#

try to determine direction of your projectile with: let dir = Vector3.Normalize(Vector3.Subtract(e.faceLocation,e.block.location))
then: projectile.applyImpulse(dir) or projectile.applyImpulse(new Vector3(-dir.x,-dir.y,-dir.z)) or projectile.applyImpulse(new Vector3(-dir.x,dir.y,-dir.z))

this should fire projectile infront of a block

glacial lark
#

thank you

solid shadow
somber badge
#

solved ?

glacial lark
#

still need help with it

#

how would I applyImpulse using an angle?

somber badge
#

how do you you indentify block facing

glacial lark
somber badge
#

@glacial lark ```
let east = [-1,0,0]
let west = [1,0,0]
let north = [0,0,1]
let south = [0,0,-1]

let face // code

let baseAngle = ({
east: 0,
south: 90,
west: 180,
north: 270
})[face]

let da = 180 / 5

function fromAngle (pitchRad, yawRad, distance = 1) {
let sinYaw = Math.sin(yawRad)
let sinPitch = Math.sin(pitchRad)
let cosYaw = Math.cos(yawRad)
let cosPitch = Math.cos(pitchRad)

return {
    x : distance * -sinYaw * cosPitch ,
    y : distance * -sinPitch ,
    z : distance * cosYaw * cosPitch
};

}

for (let i = 0; i < 180; i += da) {
let dir = fromAngle( 0, i * (Math.PI / 180) )
let scaler = 2

dir.x *= scaler
dir.y *= scaler
dir.z *= scaler

// apply impulse 

}```

glacial lark
somber badge
#

yea i was doing somethin else but switched to simple solution xd

long bough
#

i seems to be in deg

somber badge
#

oh yes