LeinneSW / PureEntities

A plugin to implements entities in pmmp
GNU Lesser General Public License v3.0
87 stars 38 forks source link

Set Motion on Entities #51

Closed ghost closed 8 years ago

ghost commented 8 years ago

How can I set motion to the Entities. I want use a chicken as a football, so i must raise the knockback. A player gets knockback, but not the chicken :c I used the EntityDamageEvent $event->getEntity()->setMotion(new Vector3(2 * (-sin($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_PI)), -sin($damager->pitch / 180 * M_PI), 2 * (cos($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_1_PI))));

inxomnyaa commented 8 years ago

You need the subevent EntityDamageByEntityEvent in the EntityDamageEvent public funktion knockbackChicken(EntityDamageEvent $event){ $entity = $event->getDamager; If($event instanceof EntityDamageByEntityEvent){ $damager = $event->getDamager; //knockbackChicken code here }}

inxomnyaa commented 8 years ago

*function

ghost commented 8 years ago

I will try it!

ghost commented 8 years ago

`
if ($event->getEntity()->getLevel()->getName()=="ProjektA"){ if ($event instanceof EntityDamageByEntityEvent) {

            if ($event->getEntity() instanceof \pocketmine\entity\Living){
                if ($event->getEntity()->getName()=="Chicken"){
                     $damager = $event->getDamager();
                    $this->getLogger()->info("YES");
                     $event->getEntity()->setMotion(new Vector3(2 * (-sin($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_PI)), -sin($damager->pitch / 180 * M_PI), 2 * (cos($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_1_PI))));

                }

        }
        `

i have also this :c

inxomnyaa commented 8 years ago

you need to get the entity before the EntityDamageByEntityEvent

ghost commented 8 years ago

`$entity = $event->getEntity(); if ($entity instanceof \pocketmine\entity\Living){ if ($event instanceof EntityDamageByEntityEvent) {

                if ($event->getEntity()->getName()=="Chicken"){
                     $damager = $event->getDamager();
                    $this->getLogger()->info("YES");
                     $entity->setMotion(new Vector3(2 * (-sin($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_PI)), -sin($damager->pitch / 180 * M_PI), 2 * (cos($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_1_PI))));

                }

        }`

It does not work. :/

inxomnyaa commented 8 years ago

you need to get the entity before the EntityDamageByEntityEvent

ghost commented 8 years ago

`if ($event->getEntity() instanceof \pocketmine\entity\Living) { if ($event->getEntity()->getName() == "Chicken") { $entity = $event->getEntity(); if ($event instanceof EntityDamageByEntityEvent) {

                    $damager = $event->getDamager();
                    $this->getLogger()->info("YES");
                    $entity->setMotion(new Vector3(2 * (-sin($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_PI)), -sin($damager->pitch / 180 * M_PI), 2 * (cos($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_1_PI))));
                }
            }`

I don't understand what you mean. It works by a player but not by the chicken. I also don't understand what you mean with "$entity = $event->getDamager;" Because the entity who should get the knockback is not the Entity who hit the chicken.

LeinneSW commented 8 years ago

I should delete method 'setMotion()' because it affects moving

ghost commented 8 years ago

Wow that is a good bugfixing!