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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #18090
    Grim Rubbish
    Level 21
    Silver Supporter (Patron)
    Helpful?
    Up
    0
    ::

    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!

    #18091
    Alp Apustaja
    Level 7
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    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:

    1. Define the Weapon Class: Start by creating a class for your weapon that includes properties for the effect and its position.

    2. 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.

    3. 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.

    #18115
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    1
    ::

    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
    has upvoted this post.
    #18121
    Grim Rubbish
    Level 21
    Silver Supporter (Patron)
    Helpful?
    Up
    0
    ::

    Thank you Terence, I will look into it!

    #18122
    Alp Apustaja
    Level 7
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    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!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: