unity从0开始摸鱼日记23,movement

本文记录了4月16日的学习心得,主要探讨了在Unity中实现精准移动的关键——接触判断,如何根据角色与环境的接触状态(如墙壁、地面)调整移动行为,以创建出色的操作感。
摘要由CSDN通过智能技术生成

4月16日

movement的关键是通过接触的判断来对玩家的不同状态进行判定,比如说,在墙上,不在墙上,在地面上,不在地面上,是否在冲刺,对状态区分的细致程度决定了你游戏的操作手感

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class Movement : MonoBehaviour
{

    private Rigidbody2D rb;
    private Animator ani;
    private Collision coll;

    public float speed = 4;
    public float jumpForce = 8;
    public float wallJumpLerp = 4;
    public float jumpTime = 0;
    public int jumpCount = 1;
    public float dashSpeed = 20;
    public float slideSpeed = 5;

    public bool isJump = false;
    public bool canMove;
    public bool wallGrab;
    public bool wallJump;
    public bool wallSlide;
    public bool isDashing;

    private bool groundTouch;
    public bool hasDashed;

    public int side = 1;
    // Start is called before the first frame update
    void Start()
    {
        canMove = true;
        rb = GetComponent<Rigidbody2D>();
        ani = GetComponent<Animator>();
        coll = GetComponent<Collision>();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void FixedUpdate()
    {
        float x = Input.GetAxis("Horizontal");
        float y = Input.GetAxis("Vertical");
        float xRaw = Input.GetAxisRaw("Horizontal");
        float yRaw = Input.GetAxisRaw("Vertical");
        Vector2 dir = new Vector2(x, y);
        Move(dir);
        if(rb.velocity.x <
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值