CG 數位學習網 > Corgi Engine 教學



遊戲角色的預製物件

Corgi Engine 提供多個遊戲角色預製物件,開啟 [ CorgiEngine > Demos > Corgi2D > Prefabs > PlayableCharacters ] 資料夾。

 

遊戲角色的動作

走路、跑步、跳躍、多重跳躍 (可設定需要的連跳次數)

斜坡上行走、向上看、爬樓梯、蹲伏與前進 、從平台跳下

開槍射擊、攀牆跳躍、攀牆垂降、短跑 ( Horizontal dash )

噴射背包 (包含粒子效果,預設按著鍵盤 2 使用噴射背包)

 

設定遊戲角色的動作

替換自行設計的遊戲角色

開啟 [ CorgiEngine > resources > PlayableCharacters ] 資料夾,使用 space-corgi-spritesheet 遊戲角色,複製角色進行修改。

 

製作不同動作的 SpriteSheet,新增一個資料夾,匯入圖檔。

預設的 Sprite Mode = Single 單圖模式,在 Sprite Editor 將無法切割,必須將 Sprite Mode 改為 Multiple 多圖模式。

按下 Apply 按鈕套用設定,然後再按 Sprite Editor 進入編輯器。

執行左上方的 Slice 切割,將切割類型設為自動 ( Type = Automatic ) ,然後按下 Slice 按鈕。

關閉 Sprite Editor 編輯器,並按下 Apply 套用修改,這個 Animation Clip 建立完成!

 

執行 [ File > New Scene ] 建立一個空白場景,僅供編輯使用。

選取剛才建立的 Animation Clip 後執行 [ GameObject > 2D Object > Sprite ] 建立一個 Sprite 物件

提示:您也可以先建立 Sprite 然後將剛才建立的 Animation Clip 拖曳到 Inspector 編輯器的 Sprite 欄位。

執行 [ Window > Animation ] 開啟動畫視窗,目前顯示的訊息:

 

按下 Create 按鈕,建立一個新動畫,輸入適當的檔案名稱後存檔。

展開 Project 專案視窗的 Animation Clip 並選取所有的姿勢(使用 Shift 鍵複選)。

將選取的姿勢拖曳到 Animation 視窗,即可完成跑步動作的設定。

 

 

開啟 [ Assets > CorgiEngine > Demos > Minimal ] 資料夾的 MinimalLevel 場景。

 

基本遊戲物件介紹

場景上有幾個遊戲需要的物件,包括:

GameManagers 遊戲管理器,處理遊戲進度(例如分數、遊戲當前狀態)、音量控制、成就規則等等。

UICamera 包括需要的UI設置,包括血條、浮動手把、分數、FPS等等,要注意的是Input Manager元件要注意有沒有啟用。

LevelManager是設定玩家角色、起始地點、開始遊戲和結束遊戲畫面淡入淡出的效果及設定Level Bounds關卡邊界。

Regular Camera除了原本照相機的功能外,還可以設定相機移動速度、相機視野,以及是否有視差效果。

Level 是遊戲關卡上所有平台物件,玩家角色的生成地點物件也放置在內。

 

創建玩家角色

開啟 [ Asset > CorgiEngine > Corgi2D > Perfabs > PlayableCharacters ] 資料夾,將space-corgi-spritesheet預製物件放入場景中,我們先來檢視一下玩家角色的元件。

 

Corgi Controller 元件 - 設定玩家的物理行為,包括重力、速度、下坡速度等。

 

Character Level Bounds 元件 - 設定玩家碰觸關卡的上下左右邊界時如何處理。

 

Character 元件 - 設定角色的種類(玩家角色還是敵人角色)、角色名稱、精靈(模型)的動作、方向,以及動畫的管理,想要快速創建角色可以按下AutoBuild Player Character或AutoBuild AI Character自動創建角色等。

 

Character Horizontal Movement 元件 - 設定玩家角色是否受到水平方向鍵控制、移動速度、著地時的特效與音效等。

Character HorizontalMovement : This component handles basic left/right movement, friction, and ground hit detection. In its inspector you can define standard movement speed, walk speed, and what effects to use when the character hits the ground after a jump/fall.

 

Character Crouch 元件 - 設定玩家是否可以蹲下、蹲下走動、及改變碰撞器的位置等。

Character Crouch : This component handles crouch and crawl behaviours. In its inspector you can determine the crouch speed, and whether or not the collider should resize when crouched (to crawl into tunnels for example). If it should, make sure you setup its new size. *

 

Character Dash 元件 - 設定玩家角色按下 F 鍵,可以衝刺的距離、速度、冷卻時間及音效等。

Character Dash : This component allows your character to dash. From the inspector you can define the distance the dash should cover, how much force to apply, and the cooldown between the end of a dash and the start of the next one

 

Character Dive 元件 - 設定玩家角色在空中按向下鍵加上 Dash 鍵後,可以往下墜落的震動程度、速度、音效等。

Character Dive : This component allows your character to dive (by pressing the dash button + the down direction while in the air). In its inspector you can define how much the camera should shake on impact, and how fast the dive should be.

 

Character Dangling 元件 -

Character Dangling : Add this component to a character and it’ll adopt a dangling stance if facing a hole in the ground. The detection is done using a raycast, whose origin and length can be setup from the inspector.

 

 

Character Jump 元件 - 用於處理玩家角色的跳躍,可設定跳躍高度、跳躍段數及音效等。

Character Jump : This component handles jumps. In its inspector you can define the jump height, whether the jump is proportional to the press length or not, the minimum air time (how long a character should stay in the air before being able to go down if the player has released the jump button), jump restrictions, how many jumps the character can perform without touching the ground again, and how long collisions should be disabled when exiting 1-way platforms or moving platforms.

 

Character Run 元件 - 允許玩家角色改變移動速度( 使用 Shift 加方向鍵跑步) ,透過 Inspector 設定跑步速度。

Character Run : This component allows your character to change speed (defined in its inspector) when pressing the run button

 

Character Jetpack 元件 - 設定玩家角色噴射背包的向上、向左右推力,以及設置燃料和音效等。

 

Character Look Up 元件 - 設定玩家角色是否可以向上看。

Character Look Up : This component allows your character to look up when pressing up while grounded. How much the camera will move in this situation is defined on the CameraController’s inspector.

 

Character Grip 元件 -

 

Character Wall Clinging 元件 - 設定玩家抓住牆壁範圍、滑落程度及音效。

 

Character Walljump 元件 - 設定玩家抓住牆壁跳躍的距離、音效。

Character Walljump : This component allows your character to perform an extra jump while wall clinging only. Here you can determine the force to apply to that jump

 

Character Ladder 元件 - 設定玩家角色爬階梯的速度、音效等。

Character Ladder : This component allows your character to climb ladders (objects with a Ladder component). From its inspector you can set the speed to apply to the character when it’s climbing a ladder.

 

Character Pause 元件 - 設定玩家是否可以暫停遊戲,並可設定暫停的音效。

注意!場景需要 InputManager 與 TimeManager 物件來讓暫停功能正常運作。

 

Character Button Avtivation 元件 - 設定玩家角色是否可以和場景物件有互動(NPC對話及觸發開關)。

 

Character Handle Weapon 元件 - 充許玩家角色使用武器,並設定既有的武器種類,請參閱 [ CorgiEngine 武器教學 ]

 

Character Push 元件 - 允許玩家角色可以推動 Pushable blocks 物件。

Character Push : This component will allow your character to push Pushable blocks. This is not mandatory, you’d be able to push objects without it, but this component will allow you to have a dedicated push animation when pushing, and override default push values. For the animation to work, you’ll need to add a “Pushable” component on your pushable blocks.

 

Health 元件 - 設定玩家角色的生命值、受傷特效、死亡時的特效、簡易動畫。

 

Character Health Bar 元件 -

 

Character Gravity 元件 - 允許玩家擁有自訂的重力方向,請參閱 [ CorgiEngine 重力教學 ]

While most features will work exactly the same whether gravity is modified or not, note that some features are “normal gravity” specific (sticking to slopes, push & pull).

 

 

 

 

 

 

 

執行 [ Window > Animator ] 開啟動畫視窗,若沒有顯示的話請選取 space-corgi-spritesheet 遊戲角色物件。

對於每個玩家角色,你會發現一個專門的動畫。Corgi Engine 使用 Mecanim 動畫系統的態機與混合樹,因此您可以輕鬆地與自己的性格取代遊戲角色的動畫。該演示使用spritesheets,但此引擎可以與任何你喜歡的動畫工具(例如使用 Spine 製作的角色動作)。