Jump to content

[1.19] Projectile entity spawns with deflection


Luckydel

Recommended Posts

Spawn:
https://ibb.co/NKnvqXk
How i would like:
https://ibb.co/BLYgwW7

 

public class BulletEntity extends AbstractBullet implements IEntityAdditionalSpawnData {
	...
	public static BulletEntity shoot(Level world, Player entity, float power, double damage, int knockback, RegistryObject<SoundEvent> soundName, float 	spreading) {
        BulletEntity entitybullet = new BulletEntity(world,entity);
        entitybullet.shootFromRotation(entity, entity.getXRot(), entity.getYRot()+0.4F, 0.0F, power, spreading);
        //entitybullet.shoot(entity.getViewVector(1).x, entity.getViewVector(1).y, entity.getViewVector(1).z, power, spreading);

        ...

I tried changing the arguments shootFromRotation, shoot. By height (y) I succeeded, but x did not. But when you turn the mouse, the coordinates of the entity are distorted
 

Actions in AbstractBullet(Identical to AbstractArrow) did not help

public abstract class AbstractBullet extends Projectile {
	...
	protected AbstractBullet(EntityType<? extends AbstractBullet> p_36717_, LivingEntity p_36718_, Level p_36719_) {
        this(p_36717_, p_36718_.getX()-0.5F, p_36718_.getEyeY()+0.5F, p_36718_.getZ(), p_36719_);
        this.setOwner(p_36718_);
        if (p_36718_ instanceof Player) {
            this.pickup = AbstractBullet.Pickup.ALLOWED;
        }

    }


 

Link to comment
Share on other sites

So, there are two parts to getting the bullet to shoot out from the camera location. For the position, you need the eye position, which has the same x/z coordinates, but a separate y coordinate (can be obtained through #getEyeY). Second, you need the rotation of the view camera. This is done through the view vector commands, though you don't need to call it three times, just store the vector.

Link to comment
Share on other sites

On 10/25/2022 at 2:07 AM, ChampionAsh5357 said:

Basically you are just setting the x and y rotation of the projectile. I was simply stating you could store the result of the vector in a variable and get the values from that.

I'm sorry, I don't understand how this will help me.
I need the projectile to spawn exactly in the center of the intersection. Right now he appears on the side. 

 

On 10/24/2022 at 4:04 AM, ChampionAsh5357 said:

Second, you need the rotation of the view camera

Am I not getting them here?

entitybullet.shootFromRotation(entity, entity.getXRot(), entity.getYRot()+0.4F, 0.0F, power, spreading);

 

 


 

Link to comment
Share on other sites

2 hours ago, Luckydel said:

I'm sorry, I don't understand how this will help me.

Well, if you don't set the rotation correct, it will go off in a different direction than from the intersection.

2 hours ago, Luckydel said:

Am I not getting them here?

That is just setting what direction it will fly off in. It does not set the position of the entity. And again, you need to set it to the player's x/y/z where the y represents the eye height as mentioned in the first post.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.