Forum begins after the advertisement:
[General] I need help with a specific weapon effect
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [General] I need help with a specific weapon effect
- This topic has 2 replies, 3 voices, and was last updated 2 weeks ago by
Alp Apustaja.
-
AuthorPosts
-
May 6, 2025 at 1:50 pm #18090::
I would like to create a weapon that basically works like the aura or the whip weapon. However, I would like the weapon effect to always be “fixed” to the player (or position x0,y0,z0). Unfortunately, the whip weapon effect always appears at a random location next to the player and “stays” there, even if the player moves in between. And the aura is unfortunately permanently active, and the effect is always displayed, so this doesn’t quite fit as well. I hope I’ve made what I’d like to achieve somewhat clear. ;-)
Thanks for your help!
May 6, 2025 at 1:56 pm #18091::To create a weapon effect that is fixed to the player (or a specified position) while avoiding the issues you mentioned with the whip and aura, you can implement a solution that updates the position of the effect based on the player’s movement. Here’s a general approach you could follow:
-
Define the Weapon Class: Start by creating a class for your weapon that includes properties for the effect and its position.
-
Update Position: In the update loop of your game, ensure that the position of the weapon effect is updated to match the player’s position.
-
Control Visibility: Implement logic to control when the effect is visible, so it only appears when the weapon is active or based on certain conditions.
Here’s a sample code snippet that outlines this approach in a pseudo-code style:
class Weapon: def __init__(self, player): self.player = player self.effect_position = (0, 0, 0) # Initial effect position self.is_active = False # State of the weapon effect def update(self): if self.is_active: # Update the position of the effect to match the player's position self.effect_position = (self.player.x, self.player.y, self.player.z) self.show_effect() def show_effect(self): # Logic to display the effect at `self.effect_position` print(f"Effect is at: {self.effect_position}") def activate(self): self.is_active = True def deactivate(self): self.is_active = False # Logic to hide the effect print("Effect is hidden.") # Example usage class Player: def __init__(self): self.x = 0 self.y = 0 self.z = 0 def move(self, dx, dy, dz): self.x += dx self.y += dy self.z += dz # Create player and weapon instances player = Player() weapon = Weapon(player) # Activate the weapon weapon.activate() # Game loop (simplified) while True: player.move(1, 0, 0) # Simulating player movement weapon.update()
Explanation:
- Weapon Class: Contains the logic for updating the effect’s position based on the player’s current coordinates.
- Update Method: Called every frame or tick to reposition the effect if the weapon is active.
- Visibility Control: You can control when to show or hide the effect based on user input or game events.
By following this pattern, you can create a weapon effect that is always fixed to the player, allowing for dynamic movement while maintaining the desired effect behavior. Adjust the visibility and effect rendering logic as per your game’s requirements.
May 6, 2025 at 6:57 pm #18115::If I recall correctly, the whip effect has an offset because the sprite’s pivot for the whip is set to either the left or the right, so when it spawns it will always spawn with an offset.
Because your effect happens in pulses, the best effect that you can use as a base for the effect you want is this:
You can follow this tutorial, then just scale up the effect to be the size that you want for your pulses. From there, you can replace some of the layers with one of the shockwave sprites here (https://kenney.nl/assets/particle-pack) and the animation will appear more “pulse-y”.
Your weapon should spawn a new GameObject for every pulse, so be sure to set Stop Action to Destroy and ensure the effect does not loop so that the particles don’t fill up your Scene over time.
You can watch this video, which goes through some basic concepts about particle effects, as well:
Let me know if these videos are useful. I originally planned to make a series of videos on them, but the initial videos were low on views so I stopped.
- 1 anonymous person
May 6, 2025 at 7:22 pm #18121May 6, 2025 at 7:26 pm #18122::You’re welcome! If you have any more questions or need further assistance as you work on your weapon effect, feel free to ask. Good luck with your project!
-
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: