Unreal入门,通过蓝图自定义Pawn视角跟随鼠标

image

1. 最简单的实现是利用Character的CharacterMovementComponent组件来实现,只用添加输入即可

1.1 新建基于Character的Pawn

image

1.2 新建GameMode

image

image

1.3 设置默认Pawn

image

1.4 添加对应鼠标XY的轴映射LookHorizontalX和LookVerticalY,名字随便取,自己开心就好,注意这里不需要定义负值

image

1.5 添加轴映射事件,并分别连线到AddControllerYawInput和AddControllerPitchInput

image

1.6 测试

image

2. 自定义Pawn视角跟随鼠标,需要自定义相机和旋转事件处理

image

2.1 定义并设置默认Pawn

image

2.2 定义并设置鼠标轴映射绑定,同上

2.3 应用旋转分量实现跟随鼠标视角

image
image

2.4 也可以只旋转相机

image
image

2.4 也可以用AddActorLocalRotation来旋转相机

image

参考

https://docs.unrealengine.com/4.26/en-US/BlueprintAPI/Pawn/Input/AddControllerPitchInput/
https://docs.unrealengine.com/4.26/en-US/BlueprintAPI/Pawn/Input/AddControllerYawInput/
https://docs.unrealengine.com/4.26/en-US/BlueprintAPI/Utilities/Transformation/AddActorLocalRotation/
https://docs.unrealengine.com/5.0/zh-CN/quick-start-guide-to-player-controlled-cameras-in-unreal-engine-cpp/

posted @ 2023-11-08 21:39  BuzzWeek  阅读(183)  评论(0编辑  收藏  举报