Posted October 23, 20222 yr 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; } }
October 24, 20222 yr 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.
October 24, 20222 yr 6 hours ago, Luckydel said: Where should I insert this vector? 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.
October 26, 20222 yr Author 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);
October 26, 20222 yr Author I understand getXRot() gives values from -180 to 180 around the player, if i make getXRot()+0.5F it will be a mistake. It seems to me to do if(getXRot()>0) +0.5F and (getXRot()<0) -0.5F not very correct Edited October 26, 20222 yr by Luckydel
October 26, 20222 yr 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.
October 26, 20222 yr Author I understood what the problem was, the central point of the model was not in the center of the projectile. Thanks anyway
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.