Forum begins after the advertisement:


Blood sprite appears at the beginning & bat flying too low

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity Blood sprite appears at the beginning & bat flying too low

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #16338
    Pool ForReal
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    my blood for enemy appers when i run and my bat flying too low

    this the video

    View post on imgur.com
    #16499
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    1
    ::

    The blood effect is still in the scene. You just need to delete the GameObject.

    has upvoted this post.
    #16570
    A_DONUT
    Level 6
    Moderator
    Helpful?
    Up
    0
    ::

    It sounds like you’re encountering two separate issues:

    1. Player blood effect appearing on enemies
      This could be due to incorrect collision handling or blood effects being mistakenly parented to the wrong object.

    2. Bat flying too low
      The bat’s position or flight height may not be set correctly in its movement logic.


    1. Fixing Blood Effect on Enemies:

    Check Particle or Blood Effect Instantiation:
    Ensure the blood effect is correctly linked to the player, not the enemy.

    • Correct Parent Assignment:
      When creating the blood effect, make sure it’s instantiated at the correct position and parented properly:

      void TakeDamage(int damage)
      {
          health -= damage;
      
          // Instantiate blood effect at player's position, not enemy
          GameObject blood = Instantiate(bloodEffectPrefab, transform.position, Quaternion.identity);
          blood.transform.SetParent(null);  // Ensures it doesn't parent to enemy accidentally
      
          if (health <= 0)
          {
              Die();
          }
      }
    • Layer/Tag Checking:
      Verify your collision detection differentiates between the player and enemies using tags or layers:

      void OnCollisionEnter2D(Collision2D collision)
      {
          if (collision.gameObject.CompareTag("Player"))
          {
              // Only apply blood effect or damage logic to the player
          }
      }

    2. Adjusting the Bat’s Flying Height:

    Check Bat Movement Logic:

    • Adjust Vertical Position:
      Ensure that the bat maintains a specific Y-axis value or follows a predefined height range:

      public float flightHeight = 3.0f;  // Desired height
      public float speed = 2.0f;
      
      void Update()
      {
          Vector3 targetPosition = player.position;  // Assume bat chases player
          targetPosition.y = flightHeight;  // Set fixed height
      
          transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
      }
    • Pathfinding Check:
      If you’re using pathfinding or waypoints, ensure they are set at the desired height.

    • Collision with Ground:
      The bat may collide with the ground or objects. Ensure its Collider is set to avoid ground collisions by:

      • Adjusting the bat’s collider height or offset.
      • Checking collision layers to avoid ground objects.

    Debugging Tips:

    • Logs and Debugging: Add Debug.Log() messages in both the blood and bat scripts to ensure they’re being called and positioned correctly.

      Debug.Log("Blood effect at position: " + transform.position);
      Debug.Log("Bat height: " + transform.position.y);
    • Check Unity Inspector: Ensure the blood effect’s Transform isn’t unintentionally tied to an enemy’s position and check the bat’s Y value in real-time.

    Let me know if you need more details or if you’d like help modifying specific code!

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

Go to Login Page →


Advertisement below: