You are a mapmaker and want to create a game implementing shooting mechanics? Here is a system that will not only enables you to shoot but also control the trajectory of the projectile.
Fully Handle Projectiles
“LeiRoF & GamerGuppy direction”, aka. LGdir – references to CPdirection (“Crushed Pixel direction”) – is a system allowing players or any entity to throw snowball-like projectiles. You can manage:
- Trajectory: this one allows you to modify the place where the projectile is heading. You can then define a trajectory “right” or create oblique trajectories. You will be able to simulate the gravity, the wind etc., the only limit is that of your imagination!
- Collisions: the projectile will be able to cross all surfaces or to bounce / stick / slide on some of them!
- Velocity: Increase, decrease or even stop the speed of a projectile during its race! You can even start it in the opposite direction at any time!
- IDs/Properties: it will be easy for you to distinguish all the projectiles as well as the person who launched them. Thus, you will know who scored the goal by throwing the ball or who to shoot who etc…
LGdir will adapt to any map as scoreboard objectives all starts with “Dir” avoid compatibility issues.
In addition, it turns out to be extremely flexible due to its “open” and organized design. You can create your custom projectiles (by putting a sheep as a projectile, making a map like SheepWars will be a breeze) and change the behavior of each independently of the others.
This system was originally designed for a more complex map and therefore implemented the ability to manage an unlimited number of projectiles at the same time and by as many players as desired!
The initial map (known as Hierarchy) also imposed an optimization constraint to which he was able to respond. Thus, the parts of the system are independent and will only activate if necessary through the implementation of an intelligent activation system. The trajectory calculation part will only light for 0.05 seconds when a player fires!
Finally and to top it off, the LGdir has received improvements making it ultra responsive. The shots will then be almost instantaneous as well as the changes of directions!
How does it work?
To understand this system, we will do reverse engineering (start by seeing the result and gradually decompose the system from the end to arrive at its foundation). For those who are brave enough, I made available very detailed explanations in the spoilers. This system will then have no secrets for you;)
Ah! There, we return to the heart of the subject! As a reminder, in order to make a projectile system, the CPdirection was based on the “Motion” tags defined according to the player’s orientation by testing each possibility. 360 degrees horizontal multiplied by 180 degrees vertical, that’s a lot of possibility (64,800 to be exact) and as many control blocks activated in a loop (especially when we had to put multiple copies of the system to have multiple speeds)!
Here, there is no question of motions because they posed too many problems. This system uses teleportation as a means of transportation.
But then the projectiles do not move smoothly and linearly but are teleported so jerky?
In theory, in practice, it is more complicated than that because it is a combination of micro-teleportations, cumulated with the animation of teleportation of the entities of Minecraft. In short, rest assured, the movements are perfectly fluid!
These teleports are made from 3 vectors (in X, Y and Z), to know how fast the projectile moves on each axis. Thus, the sum of the 3 vectors will form the vector (direction, direction and intensity) of the projectile. The motion of the projectile is then optimized by a mathematical process so that its trajectory is as accurate as possible without having as many command blocks as possibilities.
The 3 vectors are directly calculated thanks to the orientation of the player (they even deduced via a mathematical process of optimization) thanks to trigonometric formulas brought back to simple operations (addition, subtraction, division and multiplication. maths!)
How to use it?
This system has been modified many times in order to make it as simple as possible. Here is the list of useful elements to know in order to fully control the system!
- (tag) DirShoot: allows a projectile to be fired at the entity with the tag. This tag is deleted automatically as soon as the entity fired
- (tag) DirHaveShoot: this tag allows to know when the entity has just fired (useful to modify the projectile according to the shooter without modifying the LGdir). This tag is automatically placed and deleted
- (tag) DirMoving: lets know when a projectile is moving. Removing this tag will effectively stop the projectile. To make him resume his race, just give him this tag.
- (score) DirCollision: allows to manage the collisions of the projectile. Each score corresponds to a behavior (the projectile will bounce everywhere when it will have the score 1 for example). It is possible to create one’s own behavior.
- (scores) DirX, Dir Y et DirZ: allows you to manage the speed on the X, Y and / or Z axis. Changing the value will change the trajectory of the projectile. Increasing this value in a loop will have the effect of giving an oblique trajectory to the projectile.
- (score) DirSpeed: allows you to manage the overall speed of the projectile. Changing its value to 200 will multiply its speed by 2, 300 to multiply by 3, and so on. This value must not be less than 0 nor greater than 400 otherwise, the projectile will take an imprecise trajectory (by default the projectile will have a DirSpeed at 200 corresponding to a speed of 2 blocks per tick)
That’s all ! You now know all there is to know about this system!
- LeiRoF: Concept & Developement
- GamerGuppy: Developement
The creation of the LGdir has been greatly facilitated thanks to GamerGuppy, having realized a system approaching the LGdir (which has also served as a basis for work).
How to install?
To install this system, you can:
- Import schematic via MCedit software
- Install World Edit (plugin under CraftBukkit or Spigot for servers, mod “SinglePlayerCommands” for clients) and access the directory “schematics” present in the mod / plugin folder. Drag the file and go to your Minecraft and enter the commands “// schem load LGdirByLeiRoF” then “// paste” where you want to install it.
Once installed, you will need to press the buttons at the bottom of the systems named “Constant” and “Objectives”. As a precaution, break and replace the redstone blocks to update the adjacent blocks.