#Facing 180° Angle
1 messages · Page 1 of 1 (latest)
how are you determining the block face?
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: ??})
}
}
)
do you have a bundler setup to use external packages or are you just using plain scripts?
yeah, with also making the xyz to be relatively to where it faces, like disregarding the default X and Z whenever it faces north, west, etc
im just using plain scripts, are there bundlers i can use?
im very bad at these maths
#1223546390433497108 message
there's that post that shows how to use a bundler
as for what package I recommend using for math, @bedrock-oss/bedrock-boost
oh, i need npm packages, i don't know much about npms, i only know javascript and im no IT myself, i cant even install minecraft dependencies on my projects other than copying and pasting the node_modules folder for type definitions xd
yawqna
still need help with diz
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
okay, thanks, im stupid on these vector things, let me see if i got this working
thank you
same ^^
tbh i would help you with how to fire other projectiles but i have no idea how to rotate vector
solved ?
not yet
still need help with it
how would I applyImpulse using an angle?
how do you you indentify block facing
let facing = e.block.permutation.getState("minecraft:cardinal_direction")
//returns north, south, east, west
@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
}```
what does those direction variables do? it doesn't seem to be used in the code
yea i was doing somethin else but switched to simple solution xd
don't you need to convert the angle to rad before passing into fromAngle?
i seems to be in deg
oh yes