AutoMiner: RotateArm Function - Game Development Code Explanation
// AutoMiner // Token: 0x06002370 RID: 9072 RVA: 0x000C0400 File Offset: 0x000BE600 private void RotateArm(Vector3 target_dir, bool warp, float dt) { if (this.rotation_complete) { return; } // 计算目标方向与当前方向之间的角度差 float num = MathUtil.AngleSigned(Vector3.up, target_dir, Vector3.forward) - this.arm_rot; num = MathUtil.Wrap(-180f, 180f, num); // 角度差限制在-180度到180度之间 this.rotation_complete = Mathf.Approximately(num, 0f); // 如果角度差已经为0,则旋转完成 float num2 = num; if (warp) { this.rotation_complete = true; // 瞬间旋转 } else { num2 = Mathf.Clamp(num2, -this.turn_rate * dt, this.turn_rate * dt); // 根据时间差和旋转速率计算旋转角度 } this.arm_rot += num2; // 更新旋转角度 this.arm_rot = MathUtil.Wrap(-180f, 180f, this.arm_rot); // 旋转角度限制在-180度到180度之间 this.arm_go.transform.rotation = Quaternion.Euler(0f, 0f, this.arm_rot); // 更新旋转后的物体的角度 if (!this.rotation_complete) { this.StartRotateSound(); // 开始旋转音效 this.looping_sounds.SetParameter(this.rotateSound, AutoMiner.HASH_ROTATION, this.arm_rot); // 更新音效的旋转参数 return; } this.StopRotateSound(); // 停止旋转音效 }
原文地址: https://www.cveoy.top/t/topic/oSv4 著作权归作者所有。请勿转载和采集!