Started by
superProxi64
on
Topic category: Help with MCreator software
To summarize my issue, basically I have a cannon thats spawned with an item and spawns in as an entity. I want to make a system where the player can face a certain direction and when you right click the cannon, the cannon will switch to the direction your facing and launch a cannonball. The only issue is that:
1: I have no clue how to make an entity launch a projectile on demand (better yet how to even spawn a projectile on demand)
2: I have no clue how to force rotation upon an entity (also on demand) (also requiring the input of the players direction)
TL;DR: Does anyone know how to either make a block that spawns a projectile on demand or how to make an entity that shoots a projectile on demand?
You actually have a few options here. I've tested both of these, and they both worked. This will only work with an entity, but will fire like you want. At some point you'll probably want to make a custom ranged item so you can have cannonballs, but that will be a future thing.
The most important thing is to make it so that your cannot entity has no tasks in the code but still has AI enabled
Notice how the Enable AI box is still checked. This will make it so that your cannot won't be looking around on its own and messing with where it will shoot
There's two ways you can go ahead and do this. Both of these will require you to bind a procedure to the "entity is right clicked" event. In both cases you'll want to remember that Event/target entity = the cannon and Source entity = the player.
The first way to do this is as follows. This is cut and simple, firing the projectile that you want at the rotation of the player's head. It will work best if the player is right behind. Both of these code boxes can be found in the "Entity management" and "Entity data" tabs.
The alternative is to make the rotation setting separate from the firing. In this case, the cannon's rotation will be set if the player is sneaking, and fire if the player isn't.
Once you get either of these down, you'll want to mess around with the values. Pitch will determine how far up the projectile will fire. Just remember that negative numbers makes the projectile shoot higher, and you shouldn't put the value above 90 or -90. The second code block with the power, damage, and knockback will be more you'll need to mess around with to make it fly as far as you want. If it will be an exploding cannonball, there is more you'll have to do, but I won't be explaining that in this comment.
If there's anything else you need help with, tell me and I'll try to explain how.
I couldn't find "Shoot ranged item as"