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
- This topic has 2 replies, 3 voices, and was last updated 1 month, 1 week ago by A_DONUT.
-
AuthorPosts
-
November 15, 2024 at 5:00 am #16338::
my blood for enemy appers when i run and my bat flying too low
this the video
View post on imgur.com
November 23, 2024 at 1:44 pm #16499November 27, 2024 at 8:07 pm #16570::It sounds like you’re encountering two separate issues:
-
Player blood effect appearing on enemies
This could be due to incorrect collision handling or blood effects being mistakenly parented to the wrong object. -
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 itsCollider
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’sY
value in real-time.
Let me know if you need more details or if you’d like help modifying specific code!
-
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: