<P> using UnityEngine;
using System.Collections; </P>
<P>/**
* @Author : <A href="http://www.xuanyusong.com">www.xuanyusong.com</A>
*/</P>
<P>[RequireComponent(typeof(CharacterController))]
[AddComponentMenu("Character/Character Motor")] </P>
<P>public class CharacterMotor : MonoBehaviour {
// Does this script currently respond to input?
public bool canControl = true;
public bool useFixedUpdate = true;
// For the next variables, @System.NonSerialized tells Unity to not serialize the variable or show it in the inspector view.
// Very handy for organization!
// The current global direction we want the character to move in.
[System.NonSerialized]
public Vector3 inputMoveDirection = Vector3.zero;
// Is the jump button held down? We use this interface instead of checking
// for the jump button directly so this script can also be used by AIs.
[System.NonSerialized]
public bool inputJump = false;
[System.Serializable]
public class CharacterMotorMovement
{
// The maximum horizontal speed when moving
public float maxForwardSpeed = 10.0f;
public float maxSidewaysSpeed = 10.0f;
public float maxBackwardsSpeed = 10.0f;
// Curve for multiplying speed based on slope (negative = downwards)
public AnimationCurve slopeSpeedMultiplier = new AnimationCurve(new Keyframe(-90, 1), new Keyframe(0, 1), new Keyframe(90, 0));
// How fast does the character change speeds? Higher is faster.
public float maxGroundAcceleration = 30.0f;
public float maxAirAcceleration = 20.0f;
// The gravity for the character
public float gravity = 10.0f;
public float maxFallSpeed = 20.0f;
// For the next variables, @System.NonSerialized tells Unity to not serialize the variable or show it in the inspector view.
// Very handy for organization!
// The last collision flags returned from controller.Move
[System.NonSerialized]
public CollisionFlags collisionFlags;
// We will keep track of the character's current velocity,
[System.NonSerialized]
public Vector3 velocity;
// This keeps track of our current velocity while we're not grounded
[System.NonSerialized]
public Vector3 frameVelocity = Vector3.zero;
[System.NonSerialized]
public Vector3 hitPoint = Vector3.zero;
[System.NonSerialized]
public Vector3 lastHitPoint = new Vector3(Mathf.Infinity, 0, 0);
}
public CharacterMotorMovement movement = new CharacterMotorMovement();
public enum MovementTransferOnJump {
None, // The jump is not affected by velocity of floor at all.
InitTransfer, // Jump gets its initial velocity from the floor, then gradualy comes to a stop.
PermaTransfer, // Jump gets its initial velocity from the floor, and keeps that velocity until landing.
PermaLocked // Jump is relative to the movement of the last touched floor and will move together with that floor.
}
// We will contain all the jumping related variables in one helper class for clarity.
[System.Serializable]
public class CharacterMotorJumping {
// Can the character jump?
public bool enabled = true;
// How high do we jump when pressing jump and letting go immediately
public float baseHeight = 1.0f;
// We add extraHeight units (meters) on top when holding the button down longer while jumping
public float extraHeight = 4.1f;
// How much does the character jump out perpendicular to the surface on walkable surfaces?
// 0 means a fully vertical jump and 1 means fully perpendicular.
public float perpAmount = 0.0f;
// How much does the character jump out perpendicular to the surface on too steep surfaces?
// 0 means a fully vertical jump and 1 means fully perpendicular.
public float steepPerpAmount = 0.5f;
// For the next variables, @System.NonSerialized tells Unity to not serialize the variable or show it in the inspector view.
// Very handy for organization!
// Are we jumping? (Initiated with jump button and not grounded yet)
// To see if we are just in the air (initiated by jumping OR falling) see the grounded variable.
[System.NonSerialized]
public bool jumping = false;
[System.NonSerialized]
public bool holdingJumpButton = false;
// the time we jumped at (Used to determine for how long to apply extra jump power after jumping.)
[System.NonSerialized]
public float lastStartTime = 0.0f;
[System.NonSerialized]
public float lastButtonDownTime = -100f;
[System.NonSerialized]
public Vector3 jumpDir = Vector3.up;
}
public CharacterMotorJumping jumping = new CharacterMotorJumping();
[System.Serializable]
public class CharacterMotorMovingPlatform {
public bool enabled = true;
public MovementTransferOnJump movementTransfer = MovementTransferOnJump.PermaTransfer;
[System.NonSerialized]
public Transform hitPlatform;
[System.NonSerialized]
public Transform activePlatform;
[System.NonSerialized]
public Vector3 activeLocalPoint;
&nb
相关推荐
Unity3D场景漫游毕设实战:从模型处理到交互实现全流程解析
三维场景漫游是计算机图形学与虚拟现实领域的核心应用之一,它通过构建沉浸式虚拟环境,让用户能够自由探索数字空间。其技术原理涉及三维建模、实时渲染、物理模拟和人机交互等多个层面,在游戏开发、数字孪生、教育培训和文化遗产保护等领域具有重要价值。本文以热门的Unity3D引擎为基础,结合Blender等工具,详细拆解一个完整场景漫游项目的实现路径。内容涵盖从SolidWorks等工程软件模型导入、格式转换与减面优化,到地形编辑、光照烘焙与后期处理等环境搭建技巧,并深入讲解了第一人称控制器、触发交互、物品拾取等核心交
unity3D C#脚本实现鼠标拖动物体
using System.Collections; public class clickmove : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { }
Unity3d即时战斗之敌人AI和角色攻击
角色控制脚本Character.cs,为角色添加角色控制器Character controller。 using UnityEngine; using System.Collections; public class Character : MonoBehaviour { float attackInterval = 1.5f; float timer = 0; public floa
Unity3D用c#脚本修改Animator controller的weight值
本文介绍如何通过脚本修改Animator controller的layer中的weight值
Rockchip RK3568实战:手把手教你调试I2S音频驱动(附ALSA设备树配置详解)
本文提供Rockchip RK3568平台I2S音频驱动的实战调试指南。详细解析了从硬件连接到软件配置的全过程,重点涵盖ALSA驱动框架下的设备树配置、时钟计算、DMA参数设置以及常见问题(如无声、爆音)的排查与解决方法,帮助开发者快速定位并解决音频驱动难题。
TMC5130/TMC5160步进电机驱动芯片深度解析与工程实践
步进电机驱动芯片是精密运动控制系统的物理执行核心,其性能直接决定定位精度、运行噪声与系统鲁棒性。基于电流闭环控制与电压前馈调制的混合驱动原理,现代智能驱动芯片如TMC51X0系列实现了微步插补、堵转检测和片上运动规划等关键技术突破。这类芯片通过SPI寄存器级配置实现StealthChop静音驱动与SpreadCycle高动态响应模式的无缝切换,在3D打印、CNC、机器人关节等场景中显著提升能效比与控制带宽。本文围绕TMC5130与TMC5160的硬件架构差异、寄存器操作时序、驱动模式物理机制及FreeRTO
欧姆龙PLC的FinsTCP协议
三个流行的PLC: PLC 通讯协议 默认IP和端口 区别 西门子S7-1200 S7 192.168.1.201 :102 2次验证(正常连接后,第一次发不断开,第二次发断开) 三菱Q系列 MC 192.168.1.250 :4096 不验证(正常连接后,怎么发都不断开) 欧姆龙CJ-2M系列 FinsTCP 192.168.1.14 :9600 1次验证(正常连接后,第一次发断开) ...
冗余位技术在SAR ADC中的动态误差恢复机制解析
本文深入解析了冗余位技术在SAR ADC中的动态误差恢复机制,详细介绍了其基本概念、动态误差产生原因及冗余位的容错空间设计、时序松弛策略和数字校正算法。通过实际电路设计案例和数学建模,展示了冗余位技术如何显著提升ADC的精度和能效比,同时探讨了未来发展方向。
VMware 15 虚拟机安装Ubuntu 18.04
这几年在自动化、计算机之间游来游去,最近又要做机器学习相关的课题,14年做的虚拟机实在不堪重用了,OK,我们重新开始。 VMware的安装就不再赘述了,目前最新版本是15.0.2,官方下载地址: https://my.vmware.com/en/web/vmware/info/slug/desktop_end_user_computing/vmware_workstation_pro/15_0...
【华为机试真题 Python实现】分苹果
《华为机试真题》专栏含牛客网华为专栏、华为面经试题、华为OD机试真题。如果您在准备华为的面试,期间有想了解的可以私信我,我会尽可能帮您解答,也可以给您一些建议!本文解法非最优解(即非性能最优)。A,B两个人把苹果分为两堆,A希望按照它的计算规则等分苹果,他的计算规则是按照二进制加法计算,并且不计算走位,12+5=9(1100+0101=9), B的计算规则是十进制加法,包括正常进位,B希望在满足A的情况下获取苹果重量最多,输入苹果的数量和每个苹果重量,输出满足A的情况下获取的苹果总重量, 如果无法满足A的要
最新2026年《网络数据安全风险评估办法》条款解读
大型企业集团IT变革下的零信任安全体系建设方案(55页).pptx。以数据安全为核心的安全立体防御体系解决方案(41页).pptx。让数据安全合规地创造价值(15页 PPT).pptx。大型集团数据安全应急预案(57页).docx。数据安全治理与评估服务业务介绍.pptx。数据安全管理实践(17页).pptx。大数据安全架构设计方案.pptx。大数据安全规划总体方案.pptx。数据库安全综合治理方案.pptx。医疗数据安全建设方案.pptx。数据安全框架规划图.pptx。数据安全治理方案.pptx。
GPU 运维实战:H100/H800/B300 换卡与压测
(烧多久、看什么、什么算合格)。文末还给了一个能直接跑的验收判定脚本,三个真实场景的裁决输出都在。
计算机控制技术及应用
《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。
NTscan扫描工具
ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。
复分析 阿尔福斯(Ahlfors) 第三版答案 英文
答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案
RU DOS版、EFI版32bit/64bit BIOS常用工具
DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。
336



被折叠的 条评论
为什么被折叠?



