Velocity. Explication?

Hello, it’s me! again!

i’m so nooby, i don’t understand anything about velocity! i want to shoot a snowball to direction of where the player look at. but i tried a lot of things with head rotation, but it doesn’t work how i want to. If you can explain me a little bit exactly what is it. I don’t aks the answer, but how to do.

Thx for your help

Last time I did this, I just dug for a weird unnamed function to calculate the velocity for the projectile. I suggest that you don’t do that unless that’s legitimately the only way to do so.

To start with, velocity is just speed of object and direction that it’s going in. It is represented as vector.

This webpage will give you information on how vectors work in general.

https://www.mathsisfun.com/algebra/vectors.html

I’ll let someone else explain how to work velocity via sponge.

Thx to your answer.
it’s magic because i’ve already had this course at my school last year and i think it’s ok for theory.

how you said it i have to apply for sponge, and it is difficult.

If someone can help me.

@codeHusky i’m so bad, but did you use this one (i found it on other subject and i tried it:

    private static Vector3d getVelocity(Player player, double multiplier) {
        double yaw = ((player.getRotation().getX() + 90) % 360);
        double pitch = ((player.getRotation().getY()) * -1);
        double rotYCos = Math.cos(Math.toRadians(pitch));
        double rotYSin = Math.sin(Math.toRadians(pitch));
        double rotXCos = Math.cos(Math.toRadians(yaw));
        double rotXSin = Math.sin(Math.toRadians(yaw));
        return new Vector3d((multiplier * rotYCos) * rotXCos,
                multiplier * rotYSin, (multiplier * rotYCos) * rotXSin);
    }

I used a private function in Forge, so no.

Thx for your help.
any other help plz?

You should be able to create the projectile entity you want by doing what the SpongeDocs does: https://docs.spongepowered.org/master/en-US/plugin/entities/spawning.html
In their example, they create a creeper. You could modify it to be a projectile, like a snowball. The location you would use would be the player’s location + some offset to spawn it at eye level or so. Then you can, using the code you have above, get the desired velocity of the projectile and apply it using the method here: https://jd.spongepowered.org/5.0.0/org/spongepowered/api/entity/Entity.html#setVelocity-com.flowpowered.math.vector.Vector3d-
That should function as you wish, and you can play with the numbers in your getVelocity(player, multiplier) method to make it more or less powerful, etc.

Actually, you should be able to use Player.launchProjectile(). It automatically gives the projectile a proper velocity, and also sets the player as the shooter.

when i do it it spawn witout velocity it’s why i’ve to create by myself

It should have velocity already set when you fire it. File a bug report on https://github.com/SpongePowered/SpongeCommon/issues/new.