#vectors help

1 messages · Page 1 of 1 (latest)

delicate karma
#

i need like the code to trace the vector from the fireball to the player or smth

hearty grotto
#

Kb?

delicate karma
#

like make it apply a vector that is like the same as the explosion knockback, but with more knockback

#

so when it explodes, in entitydamagebyentityevent, i can have it apply that vector when they get hit by the explosion

hearty grotto
#

Oh

delicate karma
#

but idk how to trace the vector from the fireball to the player

hearty grotto
#

Get the direction of the player to the explosion center, reverse it, multiply it by something like 5 (you will have to test and figure out what value you want), and then set the player's velocity to that vector

delicate karma
hearty grotto
#

If your asking how to get the direction do Location1#subtract(Location2).toVector()

delicate karma
#

k

#

ik this is gonna sound dumb, but what do i put for #subtract

#

xD

#

like it says theres no method

hearty grotto
#

The subtract method

#

Wdym?

#

Code?

delicate karma
#

lol

#

but whats the subtract method

#

its not finding anything

#

for spigot

#

do i have to make a subtract method or smth

hearty grotto
#

Oh it's location.getDirection.subtract

delicate karma
#

o

#

thx

#

so Vector velocity = event.getEntity().getLocation().getDirection().subtract(event.getDamager().getLocation().toVector());

hearty grotto
#

Instead of reversing it just do explosionLocation.subtract(playerLocation)

#

But yes

delicate karma
#

oh

hearty grotto
#

Then multiply that vector and use it as the player's velocity

#

Wait no

delicate karma
#

lol

hearty grotto
#

What event are you using?

delicate karma
#

EntityDamageByEntityEvent

hearty grotto
#

Oh nvm thats right

delicate karma
#

lol

#

would i normalize and then multiply or multiply first

hearty grotto
#

You shouldn't need to normalize it

delicate karma
#

oh

hearty grotto
#

But if you want to then normalize after

delicate karma
#

usually when dealing with vectors normalizing is needed

#

lol

hearty grotto
#

Not for a velocity

delicate karma
#

it doesnt seem to work

#

@hearty grotto

#

it does a little more kb, but only shoots straight down when i shoot it under me

hearty grotto
#

Could you send your code?

delicate karma
#

nvm now it works i think

#

lol

#

mustve been some other plugin screwing with it

hearty grotto
#

Ok

#

Ping/dm me if you need more help but I gtg for a couple of hours

delicate karma
#

@hearty grotto it still seems to keep being weird

#

if im running and i use it, sometimes itll stop my momentum and pul me back a little

hearty grotto
#

Try adding the velocity instead of setting it

delicate karma
#

so event.getEntity().setVelocity(velocity.normalize().add(event.getEntity().getVelocity()).normalize());?

#

works a lot better, but still pulls me towards it if the explosion is a little further away

#

btw another small issue, theres quite a bit of delay between clicking and it spawning, any idea why?

@EventHandler
    public void onClick(PlayerInteractEvent event) {
        if (event.hasItem()) {
            if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) {
                if (event.getItem().getItemMeta().getPersistentDataContainer().has(new NamespacedKey(plugin, "fireball"), PersistentDataType.INTEGER)) {
                    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                        event.setCancelled(true);
                    }
                    Fireball fb = event.getPlayer().launchProjectile(Fireball.class);
                    fb.setYield(plugin.getConfig().getInt("explosionpower"));
                    fb.setShooter(event.getPlayer());
                    if (event.getPlayer().getGameMode() == GameMode.ADVENTURE || event.getPlayer().getGameMode() == GameMode.SURVIVAL) {
                        event.getItem().setAmount(event.getItem().getAmount() - 1);
                    }
                }
            }
        }
    }
#

oh wait i think ik

#

my config didnt add the new default lol

#

for knockback

#

@hearty grotto

#

lol srry i keep pinging

hearty grotto
delicate karma
#

still not applying forces right

#

@hearty grotto

#

like how does it work in stuff like hypixel

hearty grotto
#

Ok I'll test it when I get home

delicate karma
#

with mine it keeps pulling me towards the fireball sometimes

#

but like if im running and then throw it i get launched

delicate karma
hearty grotto
#

Give me like 30m and I'll see what I can do

delicate karma
#

@hearty grotto got an answer lol

hearty grotto
#

?

delicate karma
#

lol

delicate karma
hearty grotto
#

Oh sorry I was busy

delicate karma
#

xD

hearty grotto
#

Well dm me if you want more help