栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

UE4

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

UE4

绑定旋转函数 视角旋转
	//左右旋转 视角
	PlayerInputComponent->BindAxis("Turn",this,&ACharacter::AddControllerYawInput);
	//上下旋转 视角
	PlayerInputComponent->BindAxis("LookUp",this,&ACharacter::AddControllerPitchInput);
	

 

//X轴 围绕X轴旋转
&ACharacter::AddControllerRollInput
//Y轴 围绕Y轴旋转
&ACharacter::AddControllerPitchInput
//Z轴 围绕Z轴旋转
&ACharacter::AddControllerYawInput
向移动的方向旋转 .h文件里声明 移动函数
	//前后移动
	void MoveForward(float Value);
	//左右移动
	void MoveRight(float Value);

 

绑定移动函数
	//前后移动
	PlayerInputComponent->BindAxis("MoveForward",this,&AMyCharacter::MoveForward);
	//左右移动
	PlayerInputComponent->BindAxis("MoveRight",this,&AMyCharacter::MoveRight);

需要修改 移动的方法
//前后移动
void AMyCharacter::MoveForward(float Value)
{
	if(Controller != nullptr && Value != 0)
	{
		//得到控制器的旋转
		FRotator Rotation = Controller->GetControlRotation();
		//围绕Z轴旋转
		FRotator YawRotation(0.0f,Rotation.Yaw,0.0f);
		//得到这个矩阵的单位长度轴 得到这个矩阵的单位长度轴
		FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
		//向哪个方向移动
		AddMovementInput(Direction,Value);
	}

}
//左右移动
void AMyCharacter::MoveRight(float Value)
{
	if(Controller != nullptr && Value != 0)
	{
		//得到控制器的旋转
		FRotator Rotation = Controller->GetControlRotation();
		//围绕Z轴的旋转
		FRotator YawRotation(0.0f,Rotation.Yaw,0.0f);
		//得到这个矩阵的单位长度轴
		FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
		//向哪个方向移动
		AddMovementInput(Direction,Value);
	}

}

在构造方法 添加如下代码
	//如果为真,这个Pawn的滚动将被更新以匹配控制器的ControlRotation滚动(如果被PlayerController控制的话)
	bUseControllerRotationRoll = false; //x
	bUseControllerRotationPitch = false; //y
	bUseControllerRotationYaw = false; //z

	//旋转朝向移动
	//如果为真,将角色旋转到加速的方向,使用RotationRate作为旋转变化的速率。
	//覆盖UseControllerDesiredRotation。通常,您需要确保清除其他设置,例如字符上的bUseControllerRotationYaw。
	GetCharacterMovement()->bOrientRotationToMovement = true;
	//每秒旋转的变化量,当usecontrolerdesiredrotation或OrientRotationToMovement为真时使用。
	//为无限旋转速率和瞬时旋转设置一个负值。
	GetCharacterMovement()->RotationRate = FRotator(0.0f,500.0f,0.0f);

 蓝图里需要 把这几个参数 设置一下

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/698456.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号