请问如何用C++控制static mesh的旋转呢?

[复制链接]
查看2226 | 回复2 | 2016-7-17 20:16:08 | 显示全部楼层 |阅读模式
如图,我用蓝图能够实现这个功能,那么如何改写成C++版本呢? 01.JPG
Someday | 2016-7-17 22:35:23 | 显示全部楼层
1. 首先你得将两个旋转的静态组件作为成员变量声明在你的C++类中(如:AMyPawn)
2. 重写 void AMyPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent) 进行输入绑定,如
        InputComponent->BindAxis("LookRight", this, &AMyPawn::AddControllerYawInput);
        InputComponent->BindAxis("LookUp", this, &AMyPawn::AddControllerPitchInput);
3.  在自定义的 AddControllerYawInput() 、 AddControllerPitchInput() 调静态组件的 AddLocalRotation()

以上只是说思路,具体代码自己整理吧
回复 支持 反对

使用道具 举报

scorpio_b | 2016-7-18 08:33:05 | 显示全部楼层
Someday 发表于 2016-7-17 22:35
1. 首先你得将两个旋转的静态组件作为成员变量声明在你的C++类中(如:AMyPawn)
2. 重写 void AMyPawn::Se ...

谢谢版主!成员变量声明和定义这些已经在C++中做好了,然后调用蓝图的,操控static mesh可惜还不会用C++,我看了官方的Character和Vehicle,他们的左右旋转是这样的:
//人物
void AProjectileCharacter::TurnAtRate(float Rate)
{
        // calculate delta for this frame from the rate information
        AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds());
}
//车辆
void AMyProjectPawn::MoveRight(float Val)
{
        GetVehicleMovementComponent()->SetSteeringInput(Val);
}

那么我的场景中有两个static mesh对象Vehicle_Turret和Vehicle_Barrel,怎么才能获得具体对象的操作权呢?就是类似于GetVehicleMovementComponent()和GetWorld()的东西?


回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

12

主题

40

回帖

1276

积分

高阶编码师

积分
1276