Hello, I've found something new for me today, playing with Vector (not yet my BFF). I'm trying to change where the projectile will be 'send', code is as follow : PHP: public function onClickAir(Player $player, Vector3 $directionVector): bool{ $session = Fishing::getInstance()->getSessionById($player->getId()); if($session instanceof Session){ if(!$session->fishing){ $nbt = Entity::createBaseNBT($player->add(0, $player->getEyeHeight(), 0), $directionVector, $player->yaw, $player->pitch); /** @var FishingHook $projectile */ $projectile = Entity::createEntity($this->getProjectileEntityType(), $player->getLevel(), $nbt, $player); if($projectile !== null){ $projectile->setMotion($projectile->getMotion()->multiply($this->getThrowForce())); } I've try to do that (Don't know what i was doing here, but no change) : [Idea is it to add 30°/-30°, like when i try to fish ...] PHP: $randomRotation = floor(rand()/getrandmax()*30-30) ; $randomRotationRadian = $randomRotation * (M_PI/180); $cos = cos($randomRotationRadian); $sin = sin($randomRotationRadian); $newX = (10000*($directionVector->x * $cos - $directionVector->z * $sin))/10000; $newZ = (10000*($directionVector->x * $sin + $directionVector->z * $cos))/10000; var_dump($newX); var_dump($newZ); $directionVector->add($newX, 0, $newZ); Thanks
I've been able to found a solution : PHP: $projectile->setMotion($projectile->getMotion()->multiply($throwForce)); $degreeToRand = 30/(FishingLevel::getFishingLevel($player) == 0 ? 1 : FishingLevel::getFishingLevel($player)); $randomRotation = floor(rand()/getrandmax()*($degreeToRand*2)-$degreeToRand) ; $randomRotationRadian = $randomRotation * (M_PI/180); $hookMotion = $projectile->getMotion(); $theta = deg2rad($randomRotation); $cos = cos($theta); $sin = sin($theta); $px = $hookMotion->x * $cos - $hookMotion->z * $sin; $pz = $hookMotion->x * $sin + $hookMotion->z * $cos; $projectile->setMotion(new Vector3($px, $hookMotion->y, $pz)); Seems to be OK. I think my mistake was trying to add instead of set it It's easier to work on it and understand after creation, using the motion.