日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

控制`Actor`朝向,运动 Learn Unreal Engine (with C++)

發(fā)布時間:2023/12/10 c/c++ 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 控制`Actor`朝向,运动 Learn Unreal Engine (with C++) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

控制Actor的朝向,以及Actor的運動

SpaceshipBattle · fanxingin/UE4項目 - 碼云 - 開源中國 (gitee.com)

控制Actor朝向鼠標

  • 設置鼠標在游戲中可見

    • 獲取玩家控制器
    • 鼠標可見設置為true
    PC = Cast<APlayerController>(GetController()); PC->bShowMouseCursor = true;
  • 獲取鼠標與主角之間的角度

    • 獲取角度
    • 設置角度
    void ASpaceShip::LookAtCursor() {FVector MouseLocation;FVector MouseDirection;//獲取鼠標位置PC->DeprojectMousePositionToWorld(MouseLocation,MouseDirection);//獲取當前位置到目標位置所需要旋轉的角度//只在XY平面旋轉FVector TargetLoaction = FVector(MouseLocation.X, MouseLocation.Y, GetActorLocation().Z);FRotator Rotator = UKismetMathLibrary::FindLookAtRotation(GetActorLocation(), TargetLoaction);SetActorRotation(Rotator); }
  • 這樣就使主角始終朝向鼠標

  • 控制Actor運動

  • 在設置中映射活動與按鍵

    • 連續(xù)運動選擇軸映射, 例如:連續(xù)的前進
    • 不連續(xù)的運動選擇操作映射,例如:跳躍,拾取,開火

  • 輸入運動

    • 相當于將輸入先存儲
    • 讓后將存儲的向量設置給Actor
    • 然后再Tick()中調用Move()
    void ASpaceShip::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {Super::SetupPlayerInputComponent(PlayerInputComponent);PlayerInputComponent->BindAxis("MoveUp", this, &ASpaceShip::MoveUp);PlayerInputComponent->BindAxis("MoveRight", this, &ASpaceShip::MoveRight); } void ASpaceShip::MoveUp(float Value) {//MovementInput<--------------------(方向)*(值)//Movementinput---->ConsumeMovementInputVectorAddMovementInput(FVector::ForwardVector,Value); } void ASpaceShip::Move(float time) {//給對象加向量 獲取移動向量 *time為了防止速度過大穿越 檢測碰撞 AddActorWorldOffset(ConsumeMovementInputVector()* Speed * time, true);/*也可以使用這種方法獲取時間 需要頭文件*FApp::GetDeltaTime()*/ }
  • 總結

    以上是生活随笔為你收集整理的控制`Actor`朝向,运动 Learn Unreal Engine (with C++)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。