I need help. I am writing a character movement script. #150136
Replies: 1 comment 2 replies
-
Hi @XUEkfk, I understand how frustrating it can be when things don’t work as expected. Based on your description, it sounds like the character is stuck in mid-air while climbing. Here are a few quick suggestions: Climb Logic: Ensure transitions to states like Idle or Fall are working properly. Best regards, |
Beta Was this translation helpful? Give feedback.
-
This is a character movement script with states such as Idle, Walk, Dash, and Climb. However, the Climb script keeps having issues. Either the character can't climb up, or there are problems with climbing in other directions. The most critical issue is that when the character climbs to a certain height, it stops climbing but doesn't fall down. It just gets stuck in mid-air and, after some time, starts climbing again. I feel so helpless right now... the more I write, the less I know how to fix it...
`using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Rewired;
public class playerStateMgr01 : MonoBehaviour
{
[Header("角色控制")]
public float speed = 2f; // 基本速度
public float addSpeed = 5f; // 加速時的附加速度
public float longMoveDistance = 15f; // 長移動距離
public float longMoveCooldown = 0.5f; // 長移動冷卻時間
[Header("爬牆")]
public float climbDistance = 15f;
public float climbSpeed = 3f;
public float waitfor = 2f;
// 新增掉落函數
private void StartFalling()
{
anim.SetBool("isclimb", false);
isClimbing = false;
rb.velocity = Vector3.down * 5f; // 讓角色掉落
StartCoroutine(ResetClimbCooldown());
}
// 結束爬牆並進入冷卻時間
private void StopClimbing()
{
anim.SetBool("isclimb", false);
isClimbing = false;
StartCoroutine(ResetClimbCooldown());
}
// 冷卻時間
private IEnumerator ResetClimbCooldown()
{
yield return new WaitForSeconds(waitfor); // 爬牆冷卻時間
canClimb = true; // 恢復爬牆能力
}
}`
Beta Was this translation helpful? Give feedback.
All reactions