Hollow-knight开发日志(8.21)

目前开发到Crawler的移动和翻转效果

 

 

using System.Collections;
using System.Collections.Generic;
using System.Threading;
using Unity.VisualScripting;
using UnityEngine;

public class Crawler : MonoBehaviour
{
    //朝向
    private bool isFacingRight;
    //死亡施加力
    private bool isDead;
    private Rigidbody2D rigidBody;
    public float movementSpeed;
    //地面墙壁检测
    private bool isGrounded;//是否将要到悬崖
    public GameObject groundCheck;//虫子的一个子物体
    public LayerMask ground;//设置为地面
    public float circleRadiu;//半径
    //面向的物体碰撞检测
    public Collider2D facingDetector;//脸上设置碰撞体
    public ContactFilter2D contact;//接触筛选器,用于以不同方式筛选结果,例如按层遮罩、Z 深度。注意,法线角度不用于重叠测试。


    private void Start()
    {
        rigidBody = GetComponent<Rigidbody2D>();
    }

    private void Update()
    {
        Direction();
        Movement();
        FacingDetect();
    }


    /// <summary>
    /// 检测朝向
    /// </summary>
    private void Direction()
    {
        if(transform.localScale.x == 1)
        {
            isFacingRight = true;
        }
        else if(transform.localScale.x == -1)
        {
            isFacingRight = false;
        }
    }

    /// <summary>
    /// 移动
    /// </summary>
    private void Movement()
    {
        if (!isDead)
        {
            if (isFacingRight)
            {
                rigidBody.velocity = Vector2.right * movementSpeed;  
            }
            else
            {
                rigidBody.velocity = Vector2.left * movementSpeed;
            }
        }
    }

    /// <summary>
    /// 面向检测 (有两个可能性一是快到悬崖 二是撞到墙壁)
    /// </summary>
    private void FacingDetect()
    {
        if (isDead)
        {
            return;
        }
        //是否碰到地面或者墙壁 在一个圆圈内检测是否碰到相应的LayerMask
        isGrounded = Physics2D.OverlapCircle(groundCheck.transform.position,circleRadiu,ground);
        if(!isGrounded) //检测到快离开地面 回头
        {
            Filp();
        }
        else//检测虫子碰到了几个碰撞体 count大于0 就是撞墙了回头
        {
            int count = Physics2D.OverlapCollider(facingDetector, contact, new List<Collider2D>());
            if(count > 0)
            {
                Filp();
            }
        }
        

       
    }

    /// <summary>
    /// 碰到墙壁后翻转
    /// </summary>
    private void Filp()
    {
        Vector2 vector = transform.localScale;
        vector.x *= -1;
        transform.localScale = vector;

    }
    

}

其中 Physics2D.OverlapCircle 的unity 相关文档https://docs.unity.cn/cn/2022.3/ScriptReference/Physics2D.OverlapCircle.html

和 Physics2D.OverlapCollider 的unity 相关文档

https://docs.unity.cn/cn/2022.3/ScriptReference/Physics2D.OverlapCollider.html

注意设置上的

### 回答1: 您的问题中似乎有一个错别字,应该是 "hello world" 而不是 "hollow world"。那么,回答您的问题,C语言中的 "hello world" 程序通常是用于演示如何输出一段文本到屏幕上。以下是一个简单的 "hello world" 程序示例: ``` #include <stdio.h> int main() { printf("Hello, world!\n"); return 0; } ``` 这个程序会输出 "Hello, world!" 字符串到控制台,并在字符串末尾加上一个换行符。 ### 回答2: 在C语言中,实现"hollow world"可以通过以下代码: ``` #include <stdio.h> int main() { printf("hollow world\n"); return 0; } ``` 以上代码使用C标准库中的stdio.h头文件,其中包含了printf函数,可以在屏幕上打印输出。在main函数中,使用printf函数打印"hollow world",并且在最后通过return 0;语句表示程序正常结束。 执行该程序,控制台将打印输出"hollow world"。这是一个非常简单的示例程序,展示了C语言中打印输出的基本用法。 ### 回答3: "C语言 hollow world" 实际上是一个常见的错误,正确的应该是 "Hello World"。 "Hello World" 是一种传统的计算机编程任务,用于展示新手在编写简单程序时的基本语法和程序结构。它通常是学习一门新的计算机编程语言的第一个例子。 以C语言为例,下面是一个简单的 "Hello World" 程序: #include <stdio.h> int main() { printf("Hello, World!"); return 0; } 这段程序通过 "printf" 函数输出字符串 "Hello, World!" 到屏幕上。 解释一下程序的几个关键部分: - "#include <stdio.h>" 指令引入了 "stdio.h" 头文件,这是C语言标准库提供的输入输出功能的头文件。 - "int main() { ... }" 是C程序的主函数,也是程序开始执行的地方。 - "printf" 是C语言标准库中的一个函数,用于输出格式化的文本到标准输出设备(通常是屏幕)。 当我们编译并运行这个程序时,它会输出 "Hello, World!" 到屏幕上,表示程序运行成功。 "Hello World" 作为计算机编程的传统任务,无论是在C语言还是其他编程语言中,都是一个非常基础和重要的起点。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值