Forum begins after the advertisement:
Better way to make floor and monster get flipped
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › Better way to make floor and monster get flipped
- This topic has 6 replies, 2 voices, and was last updated 3 weeks, 6 days ago by pepecry.
-
AuthorPosts
-
October 20, 2024 at 4:21 pm #16120::
Hi. So when I testing the mob and player moving in the scene. When they move to some place with the box collider higher just a little bit that very hard to see unless we zoom in very close, they get stuck, even if it’s the monster or player. The gap is very close as the below img
Did you guys have any idea to make plaer, monster, etc… step to the next floor with a little gap or must I adjust it equal by my hand?
And another question that for some reason, my fly moster if in not chase stage, it looking normally but when the player get close, the enemy will chase but with the flipping side with the player as the video below
Flipped monster
here the flip codevoid skull_flip() { if(Move.Instance.transform.position.x < transform.position.x) { Sr.flipX = true; } else { Sr.flipX = false; } }
Tks you guys
October 20, 2024 at 9:07 pm #16121::Hi, one more efficient way is to make an empty game object the parent of the long platform/row of platforms and use the ground tag and box collider compoments in that parent, it will work the same way, and it only requires one long box collider for the group of sprites
Regarding the flip function, try using the script that is found in the tutorial series
void skull_flip() { sr.flipX = Move.Instance.transform.position.x < transform.position.x; }
If the problem still persists, send your full skull script and enemy script
October 21, 2024 at 7:14 pm #16131::About the ground I made like your recommend and it work perfectly. Thank you alot but the FireSKull is still not work. I still got flipped when chasing player.
for the code. Here the full scriptusing System.Collections; using System.Collections.Generic; using UnityEngine; public class FIreSkull : Enemy { [SerializeField] private float chaseDistance; [SerializeField] private float stunDuration; float stunTimer; // Start is called before the first frame update protected override void Start() { base.Start(); ChangeState(EnemyStates.Skull_Idle); } protected override void UpdateEnemyStates() { float _chasedist = Vector2.Distance(transform.position, Move.Instance.transform.position); switch (GetCurrentEnemyStates) { case EnemyStates.Skull_Idle: rb.velocity = new Vector2(0, 0); if (_chasedist < chaseDistance) { ChangeState(EnemyStates.Skull_Chase); } break; case EnemyStates.Skull_Chase: rb.MovePosition(Vector2.MoveTowards(transform.position, Move.Instance.transform.position, Time.deltaTime * speed)); skull_flip(); if (_chasedist > chaseDistance) { ChangeState(EnemyStates.Skull_Idle); } break; case EnemyStates.Skull_Stunned: stunTimer += Time.deltaTime; if(stunTimer > stunDuration) { ChangeState(EnemyStates.Skull_Idle); stunTimer = 0; } break; case EnemyStates.Skull_Dead: Death(Random.Range(5, 10)); break; } } // Update is called once per frame public override void EnemyHit(float _DmgDone, Vector2 _hitDirection, float _hitForce) { base.EnemyHit(_DmgDone, _hitDirection, _hitForce); if (health > 0) { ChangeState(EnemyStates.Skull_Stunned); } else { ChangeState(EnemyStates.Skull_Dead); } } protected override void Death(float _destroyTime) { rb.gravityScale = 12; base.Death(_destroyTime); } protected override void ChangeCurrentAnimation() { anim.SetBool("Idle", GetCurrentEnemyStates == EnemyStates.Skull_Idle); anim.SetBool("Chase", GetCurrentEnemyStates == EnemyStates.Skull_Chase); anim.SetBool("Stun", GetCurrentEnemyStates == EnemyStates.Skull_Stunned); if(GetCurrentEnemyStates == EnemyStates.Skull_Dead) { anim.SetTrigger("Death"); int DeadCorpse = LayerMask.NameToLayer("DeadCorpse"); } } void skull_flip() { Sr.flipX = Move.Instance.transform.position.x < transform.position.x; } }
October 21, 2024 at 11:21 pm #16133::Could i take a look at your animator for skull chase? your script does not seem to be the issue, so there might be other causes
October 23, 2024 at 6:36 pm #16151::Sorry for replying late. I got the video of skull animation here for you and a test when start the game too. Here is the video
animation & test
Tks you for replying and again sorry for replying lateOctober 23, 2024 at 10:30 pm #16153::Ok in your case, since your skull is facing the other direction by default compared to our bat (it faces the left instead of the right) , your skull flip should look like this
void skull_flip() { Sr.flipX = Move.Instance.transform.position.x > transform.position.x; }
let me know if there is still an issue for this
October 25, 2024 at 4:29 pm #16173 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: