ue4 weapon
UE4版本4.17,不同版本api可能有差异
静态
1 在骨骼上加socket
在socket上右键-添加浏览资源-找到要添加的那个道具(这个只用来看效果,调位置,不会显示到最终效果中),调整socket位置,知道道具位置合适为止
2 在角色bp上,添加一个staticMesh到Mesh节点下
设置父项插槽到刚才创建的socket,选择自己要使用的道具模型
动态(蓝图)
1 创建骨骼socket,步骤同上
2 用蓝图创建跟上面静态一样的结构
动态(代码)
// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h"
#include "GameFramework/Character.h"
#include "TLog.h"
#include "Runtime/Engine/Classes/Engine/EngineTypes.h"
#include "Runtime/Engine/Classes/Components/InputComponent.h"
#include "Runtime/Engine/Classes/Components/StaticMeshComponent.h"
#include "Runtime/Engine/Classes/Engine/SkeletalMeshSocket.h"
#include "MyCharacter.generated.h" UCLASS()
class NDEMO_CHANGEWEAPON_API AMyCharacter : public ACharacter
{
GENERATED_BODY() public:
// Sets default values for this character's properties
AMyCharacter(); protected: virtual void BeginPlay() override; public: virtual void Tick(float DeltaTime) override; virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; //这里武器加载的是个单独的UStaticMeshComp
void WeaponAttach1();
void WeaponDettach1(); //之类武器加载的是个Actor类型的蓝图,这种较好,方便做复合物体一起绑到角色身上
void WeaponAttach2();
void WeaponDettach2(); UStaticMesh* TUStaticMesh;
};
MyCharacter.cpp
#include "MyCharacter.h" AMyCharacter::AMyCharacter()
{
PrimaryActorTick.bCanEverTick = true;
static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("StaticMesh'/Game/model/Effects/Meshes/Items/S_Sword_Basic.S_Sword_Basic'"));
if (SphereVisualAsset.Succeeded())
{
TUStaticMesh = SphereVisualAsset.Object;
}
} void AMyCharacter::BeginPlay()
{
Super::BeginPlay();
} void AMyCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
} void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
//测试默认按钮绑定,不用再手动设置输入 InputComponent->BindAction("Custom_Z", IE_Pressed, this, &AMyCharacter::WeaponAttach1);
InputComponent->BindAction("Custom_X", IE_Pressed, this, &AMyCharacter::WeaponDettach1); InputComponent->BindAction("Custom_V", IE_Pressed, this, &AMyCharacter::WeaponAttach2);
InputComponent->BindAction("Custom_B", IE_Pressed, this, &AMyCharacter::WeaponDettach2);
} void AMyCharacter::WeaponAttach1()
{
UE_LOG(TLog, Warning, TEXT("WeaponAttach1"));
UStaticMeshComponent* C = NewObject<UStaticMeshComponent>(this, "TestWeapon");
this->AddOwnedComponent(C);
C->RegisterComponent();
C->SetStaticMesh(TUStaticMesh);
C->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
C->SetWorldScale3D(FVector(0.8f));
C->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, TEXT("hand_right_socket")); } void AMyCharacter::WeaponDettach1()
{
UE_LOG(TLog, Warning, TEXT("WeaponDettach1"));
} void AMyCharacter::WeaponAttach2()
{ TSubclassOf<AActor> WeaponClass = LoadClass<AActor>(NULL, TEXT("Blueprint'/Game/item/TWeapon.TWeapon_C'")); AActor* MeleeWeapon = GetWorld()->SpawnActor<AActor>(WeaponClass, FVector(0,0,0), FRotator(0,0,0)); if (MeleeWeapon)
{
//通过名字获得骨骼绑点
const USkeletalMeshSocket *socket = GetMesh()->GetSocketByName("hand_right_socket");
//绑定武器模型到骨骼挂点上
socket->AttachActor(MeleeWeapon, GetMesh());
} } void AMyCharacter::WeaponDettach2()
{
UE_LOG(TLog, Warning, TEXT("WeaponDettach2"));
}
Loaction Rule说明
Keep Relative:
将actor在当前场景中的transform移到parent(Socket)中。(当actor在world中处于原始transform时,它最终效果就是在Socket的预览中的效果。
Keep World:
保持actor在当前场景中的transform,对socket设置transform没有意义。但如果socket移动旋转缩放,会跟随相应移动旋转缩放。
Snap to Target:(最常使用)
使用Socket设置的transform,最终效果与actor在当前场景中的transform无关,最终效果等于socket中预览看到的效果。
DetachFromActor要注意,只有Keep Relative和Keep World选项。
如果使用 Snap to Target 进行attach,那么Keep World让Detach之后对保持之前在Socket调整后的最终尺寸到新的场景中(建议使用该方法);如果使用Keep Relative,则会让尺寸使用物体原始尺寸。
特殊问题记录
ue4 weapon的更多相关文章
- UE4杂记
一些学习UE4时的笔记,转载请注明出处. ☆ UE4逻辑 Actor 是由 AActor 类派生而来的类实例:能被放入游戏世界场景的所有游戏性对象的基础类.对象是继承自 UObject 类的类实例:虚 ...
- UE4蓝图与C++交互——射击游戏中多武器系统的实现
回顾 学习UE4已有近2周的时间,跟着数天学院"UE4游戏开发"课程的学习,已经完成了UE4蓝图方面比较基础性的学习.通过UE4蓝图的开发,我实现了类似CS的单人版射击游戏,效 ...
- UE4物理模块(三)---碰撞查询(上)
在前一文中介绍了如何在UE4中创建简单碰撞或者直接使用其mesh表示的复杂碰撞: Jerry:UE4物理模块(二)---建立物体碰撞zhuanlan.zhihu.com 那么在拿到碰撞之后,就可以进 ...
- 【UE4 设计模式】建造者模式 Builder Pattern
概述 描述 建造者模式,又称生成器模式.是将一个复杂的对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. 建造者模式将客户端与包含多个组成部分的复杂对象的创建过程分离,客户端无需知道复杂 ...
- UE4新手引导之下载和安装虚幻4游戏引擎
1) 进入虚幻4的官方主页(https://www.unrealengine.com/) 这里你可以获得关于虚幻4的最新资讯,包括版本更新.博客更新.新闻和商城等.自2015年起,该引擎已经提供免费下 ...
- UE4新手引导入门教程
请大家去这个地址下载:file:///D:/UE4%20Doc/虚幻4新手引导入门教程.pdf
- ue4 c++学习推荐
我由易到难推荐,不过在此之前还是先看看官方对于VS设置的推荐: https://docs.unrealengine.com/latest/INT/Programming/Development/Vis ...
- 如何创建独立的UE4服务端
原文作者:@玄冬Wong 转载请注明原文出处:http://aigo.iteye.com/blog/2268777 这是论坛上对UE服务端功能的回答,意思是UE4提供了主流MMO网游服务端所具备的特性 ...
- 《Inside UE4》目录
<Inside UE4>目录 InsideUE4 UE4无疑是非常优秀的世界上最顶尖的引擎之一,性能和效果都非常出众,编辑器工作流也非常的出色,更难得宝贵的是完全的开源让我们有机会去从中吸 ...
随机推荐
- Spring/Java error: namespace element 'annotation-config' … on JDK 1.5 and higher
Extract the jar file: mkdir spring cd spring jar xvf ../spring.jar Check the Spring version in META- ...
- (Android)react-native-splash-screen实践-解决react-native打包好后启动白屏的问题
1.安装 npm i react-native-splash-screen --save or yarn add react-native-splash-screen --save 2.自动配置 re ...
- Qt — 子窗体操作父窗体中的方法
父窗体与子窗体各自的代码如下: 1. 父窗体的代码: void FartherWindow::addactions() { SubWindow subwindow(this); // 把父窗体本身t ...
- IOS AFNetWorking 设置超时时间
(原创经验总结) 1.关于AF 超时的说法 系统默认的timeInterval 是60s ASI默认是10s 但是有一个说法是 AF “AFN在GET条件下设置的NSURLRequest能起作用, ...
- ubuntu tomcat 配置及使用细节
1.改端口号(两个) vi server.xml 一个是http协议端口 <Connector port="8091" protocol="HTTP/1.1&qu ...
- Module.exports和exports的区别
原文链接: https://www.ycjcl.cc/2017/02/10/module-exportshe-exportsde-qu-bie/ 学习Seajs时,看到了exports.doSomet ...
- Hadoop- 集群时间同步
集群的时间要同步 * 找一台机器 时间服务器 * 所有的机器与这台机器时间进行定时的同步 比如,每日十分钟,同步一次时间 # rpm -qa|grep ntp # vi /etc/ntp.conf # ...
- 检测 iOS 系统网络权限被关闭
背景 一直都有用户反馈无法正常联网的问题,经过定位,发现很大一部分用户是因为网络权限被系统关闭,经过资料搜集和排除发现根本原因是: 第一次打开 app 不能访问网络,无任何提示 第一次打开 app 直 ...
- kvm初体验之七:attach usb storage device to a VM
1. virsh attach-disk vm1 /dev/sdb sdc 将host上的/dev/sdb挂载到vm1的/dev/sdc上 2. virsh detach-disk vm1 sdc 将 ...
- 分享知识-快乐自己:2017IDEA破解教程
首先 修改host文件: 文件路径:C:\Windows\System32\drivers\etc\hosts 修改:将“0.0.0.0 account.jetbrains.com”追加到hosts文 ...