Create your own guns in PB2

Tutorials and guides for Plazma Burst and community features.

Create your own guns in PB2

Postby ditzy » 12 October 2019, 18:07

Was the v1.32 update not enough to quench your thirst for new weapons? Have no fear, custom guns are here!

Using the provided trigger system, you can now create your own guns for PB2. It's a somewhat limited system, however, and is only suitable for SP maps. (The trigger system should be adaptable for MP, but would require more complexity)
For an explanation on how the math works, take a look at the bottom spoilers.

Custom Guns

Open sourced so you guys can create your own custom guns.
  • The weapon model can be changed by replacing the #d/gunModel*1 decoration
  • Weapon stats can be set in #setUp*1
Note: the current trigger system only allows for the gun to be used by one player.

Map ID: ditzy-customgun
Map Page Link: https://www.plazmaburst2.com/?s=9&a=&m=ditzy-customgun
Map Demo Link: https://www.plazmaburst2.com/?s=2&map=ditzy-customgun
Map Source Link: https://www.plazmaburst2.com/level_edit ... -customgun

----

It uses the same trig system as the can of soda, which can be found here:
Map demo: https://www.plazmaburst2.com/?s=2&map=ditzy-soda
Map source: https://www.plazmaburst2.com/level_edit ... zy-soda&a=

Below is an explanation of how the math for atan2 works.
Spoiler: Show More
Let's say you're holding a can of soda 2 feet away from you, at arm level (0°). Now let's say you lower your arm. The soda is still 2 feet away from you, but now it's 30° below your shoulders. Let's say you raise your arm. The soda is now 30° above your shoulders.

Not only do we need to figure out how far away the can of soda is from our player, but we need to know at what angle it is.

How do we find the angle? We can use the atan2 method.

For our purposes, atan2 calculates the angle between two straight lines. The first line is a horizontal line running along the x axis (The lines is at 0°). The second line is a line that's drawn between point A and point B. In this instance point B will be our arm, and point A will be our hand.

If you take a look at the atan2 trigger action, you'll notice that there's only room to input the x and y positions of 1 point. That's because the atan2 method actually calculates the angle between point A and grid position 0,0 (This is what the computer considers point B).

However, we need point B to be the location of the arm to get accurate angles. How do we do this? If we subtract the position of the arm from the position of the hand, the result will give us a position that's relative to grid position 0,0. We can put that relative value into the atan2 method to get us an angle that accurately reflects the angle of the player's hands.

Now that we have the angle that the player is holding the can of soda, we need to figure out how far away the can of soda is from the player. Doing that is simple enough. We perform the sin and cos methods on our angle. We can then multiply the sin and cos values by the distance our can of soda had when at arms level (0°).

Finally, with a little more math(mainly finishing the calculations for the player's position) we have a finished trigger system that allows you to hold a can of soda!

New math for the custom guns.
Spoiler: Show More
All that's really added is a trigger action that rotates the gun to the angle that was given by the atan2 function, and another trigger system to check if the gun is upside down, in which case the image will be flipped on the y axis to correct it.
Sometimes draws ponies
Sometimes draws ponies
Sometimes draws ponies
User avatar
ditzy
Advanced Usurpation Soldier [150]
 
Posts: 169
Joined: 1 December 2017, 01:20
Location: Ponyville

Re: Create your own guns in PB2

Postby phsc » 12 October 2019, 18:09

casual reminder that cans of soda are useless
User avatar
phsc
Noir Lime [600]
 
Posts: 694
Joined: 27 July 2013, 13:58
Location: Brazil

Re: Create your own guns in PB2

Postby Jason Eden » 12 October 2019, 18:46

Eric should just allow using custom gun images like he did with decorations and backgrounds. This would make things much easier and more effective.

-EDIT- I still think this "can of soda" trigger system is useless. Why? Because of this:







I would prefer to use original old weapons because they don't have such ridiculous issues. I do admit that you, Ditzy, are a way more experienced in creating trigger systems than me, but I would suggest you to focus on creating trigger systems that are practical.
User avatar
Jason Eden
Falkok [250]
 
Posts: 275
Joined: 8 December 2018, 14:30

Re: Create your own guns in PB2

Postby ditzy » 12 October 2019, 20:47

I'll admit that the system is limited, but I don't think that makes it a waste of time. The best way to get better at something is just to mess around with it. In this case, it's triggers.

The system could be applicable in some niche instance, so I just thought I'd share it here in case anyone wants to actually use it.
Sometimes draws ponies
Sometimes draws ponies
Sometimes draws ponies
User avatar
ditzy
Advanced Usurpation Soldier [150]
 
Posts: 169
Joined: 1 December 2017, 01:20
Location: Ponyville

Re: Create your own guns in PB2

Postby Jason Eden » 14 October 2019, 17:10

You can lock this topic now, Ditzy.
User avatar
Jason Eden
Falkok [250]
 
Posts: 275
Joined: 8 December 2018, 14:30


Return to Tutorials

Who is online

Users browsing this forum: No registered users



cron