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

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #16120
    pepecry
    Level 7
    Participant
    Helpful?
    Up
    0
    ::

    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

    The floor gap 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 moster Flipped monster here the flip code
    <code>void skull_flip()
    {
        if(Move.Instance.transform.position.x < transform.position.x)
        {
            Sr.flipX = true;
        }
        else
        {
            Sr.flipX = false;
        }
    }</code>

    Tks you guys

    #16121
    Chloe Lim
    Level 10
    Moderator
    Helpful?
    Up
    0
    ::

    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

    <code>void skull_flip()
        {
            sr.flipX = Move.Instance.transform.position.x < transform.position.x;
        }</code>

    If the problem still persists, send your full skull script and enemy script

    #16131
    pepecry
    Level 7
    Participant
    Helpful?
    Up
    0
    ::

    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 script

    <code>using 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;
        }
    }
    </code>
    #16133
    Chloe Lim
    Level 10
    Moderator
    Helpful?
    Up
    0
    ::

    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

    #16151
    pepecry
    Level 7
    Participant
    Helpful?
    Up
    0
    ::

    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 video animation & test Tks you for replying and again sorry for replying late
    #16153
    Chloe Lim
    Level 10
    Moderator
    Helpful?
    Up
    0
    ::

    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

    <code>    void skull_flip()
        {
           Sr.flipX = Move.Instance.transform.position.x > transform.position.x;
        }
    </code>

    let me know if there is still an issue for this

    #16173
    pepecry
    Level 7
    Participant
    Helpful?
    Up
    0
    ::

    Tks you. It’s work correctly now

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

Go to Login Page →


Advertisement below: