值作思路:
1.假设 A 物体需要指向 B 物体的方向
2.第一步: 需要获取两个物体的位置, 可通过 GetActorLocation() 方法获取
3.第二步: 需要获取两个物体的旋转值偏移量,可通过UE引擎自带的 FindLookAtRotation 函数获取
4.第三步: 获取旋转插值, 可通过RInterpTo函数实现 用RInterpTo 函数主要是为了使动画不僵硬,也可直接通过第四步完成设置
5.第四步: 最后通过设置A的旋转值,使A的旋转值指向B
蓝图连接方法,请到下方链接中的网站里查看(该网站可直接复制蓝图):
/blueprint/dtkxu1id/
代码如下:
1.
//1.这段代码在tick中运行,也可以自行写定时器
//设置旋转
FRotator LookAtYaw = GetLookAtRotationYaw(CombatTraget->GetActorLocation());
//设置旋转过渡,使动画不僵硬
FRotator InterpRotation = FMath::RInterpTo(GetActorRotation(), LookAtYaw, DeltaTime, InterpSpeed);
SetActorRotation(InterpRotation);
2.获取旋转偏移量代码如下:
FRotator AMain::GetLookAtRotationYaw(FVector Target) {
//获取两个目标之间的偏移量
FRotator LookAtRotation = UKismetMathLibrary::FindLookAtRotation(GetActorLocation(), Target);
FRotator LookAtRotationYaw(,,);
return LookAtRotationYaw;
}
我是UE4新人,如果有错漏的地方,还请多多见谅
————————————————
版权声明:本文为****博主「岚天大大」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:/qq_34970171/article/details/115153151