UE4.9:移动角色(未设置位置)
UE4.9: Move character (not set location)
我正在从我编写的外部应用程序发送命令。此外部应用程序正在通过 UDP 将键盘上按下的键发送到 UE4。
当UE4收到消息(按下的键,例如:'w
'),我想让角色向前走(只有1个字符)。
while (true)
{
int32 bytes_read = 0;
if (Socket->Recv(data, sizeof(data), bytes_read)){
data[bytes_read] = 0;
//Should I use this, instead of SetActorLocation?
APlayerController* playerController = World->GetFirstPlayerController();
ACharacter* myCharacter = UGameplayStatics::GetPlayerCharacter(World, 0);
FVector characterLocation = myCharacter->GetActorLocation();
FVector newCharacterLocation = characterLocation + FVector(10, 0, 0);
//This just moves the character, but does not walk and no collision is included
myCharacter->SetActorLocation(newCharacterLocation);
//FPlatformProcess::Sleep(0.1);
}
}
注意:循环正在另一个线程上执行
SetActorLocation()
在移动角色时对我不起作用,但本质上只是 'teleporting'。我想指示角色像我在玩游戏一样移动并以正常方式控制角色。
我想通过我的外部应用程序控制角色。应该怎么做才能让角色动起来,就好像自己在玩游戏一样,按下,eg:'w
',向前移动?
我想通了...
while (true)
{
int32 bytes_read = 0;
if (Socket->Recv(data, sizeof(data), bytes_read)){
data[bytes_read] = 0;
ACharacter* myCharacter = UGameplayStatics::GetPlayerCharacter(World, 0);
myCharacter->AddMovementInput(FVector(10, 0, 0), 5.0);
}
}
我正在从我编写的外部应用程序发送命令。此外部应用程序正在通过 UDP 将键盘上按下的键发送到 UE4。
当UE4收到消息(按下的键,例如:'w
'),我想让角色向前走(只有1个字符)。
while (true)
{
int32 bytes_read = 0;
if (Socket->Recv(data, sizeof(data), bytes_read)){
data[bytes_read] = 0;
//Should I use this, instead of SetActorLocation?
APlayerController* playerController = World->GetFirstPlayerController();
ACharacter* myCharacter = UGameplayStatics::GetPlayerCharacter(World, 0);
FVector characterLocation = myCharacter->GetActorLocation();
FVector newCharacterLocation = characterLocation + FVector(10, 0, 0);
//This just moves the character, but does not walk and no collision is included
myCharacter->SetActorLocation(newCharacterLocation);
//FPlatformProcess::Sleep(0.1);
}
}
注意:循环正在另一个线程上执行
SetActorLocation()
在移动角色时对我不起作用,但本质上只是 'teleporting'。我想指示角色像我在玩游戏一样移动并以正常方式控制角色。
我想通过我的外部应用程序控制角色。应该怎么做才能让角色动起来,就好像自己在玩游戏一样,按下,eg:'w
',向前移动?
我想通了...
while (true)
{
int32 bytes_read = 0;
if (Socket->Recv(data, sizeof(data), bytes_read)){
data[bytes_read] = 0;
ACharacter* myCharacter = UGameplayStatics::GetPlayerCharacter(World, 0);
myCharacter->AddMovementInput(FVector(10, 0, 0), 5.0);
}
}