14.Change Character Speed & Material
BatteryCollectorCharacter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 |
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "GameFramework/Character.h"
#include "BatteryCollectorCharacter.generated.h"
UCLASS(config=Game)
class ABatteryCollectorCharacter : public ACharacter
{
protected:
// APawn interface
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
// End of APawn interface
/*CAlled when we press a key to collect any pickups inside the CollectionSphere*/
UFUNCTION(BlueprintCallable, Category = "Pickups")
void CollectPickups();
/**The starting power level of our character*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Power", Meta = (BlueprintProtected = "true"))
float InitialPower;
/*Multiplier for character speed*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Power", Meta = (BlueprintProtected = "true"))
float SpeedFactor;
/**Speed when power level = 0*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Power", Meta = (BlueprintProtected = "true"))
float BaseSpeed;
UFUNCTION(BlueprintImplementableEvent, Category = "Power")
void PowerChangeEffect();
private:
/**Current power level of our character*/
UPROPERTY(VisibleAnywhere, Category = "Power")
float CharacterPower;
|
cs |
BatteryCollectorCharacter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 |
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "BatteryCollector.h"
#include "BatteryCollectorCharacter.h"
#include "Pickup.h"
#include "BatteryPickup.h"
//////////////////////////////////////////////////////////////////////////
// ABatteryCollectorCharacter
ABatteryCollectorCharacter::ABatteryCollectorCharacter()
{/**set a base power level for the character*/
InitialPower = 2000.0f;
CharacterPower = InitialPower;
/**set the dependence of the speed on the power level*/
SpeedFactor = 0.75f;
BaseSpeed = 10.0f;
}
/*called when power is incereased or decreased*/
void ABatteryCollectorCharacter::UpdatePower(float PowerChange){
//Change power
CharacterPower = CharacterPower + PowerChange;
//change speeed based on power
GetCharacterMovement()->MaxWalkSpeed = BaseSpeed + SpeedFactor*CharacterPower;
//call visual effect
PowerChangeEffect();
} |
cs |
16,17)파워 레벨에 따라 속도를 설정함
20~)파워가 늘거나 줄면 호출됨
22) 캐릭터 파워변경
24) 캐릭터 파워를 기준으로 속도변화
24) CharacterMovementCOmponent는 모든캐릭터들에 include 된 것이다.
BatteryCollectorCharacter가 Character클래스에서 상속을 받기 때문이다.
따라서 달리거나 점프하는 등 Biped 타입이 할 수 있는 모든 운동 기능을 이미 구성한
CharacterMovementComponent를 통해 받게 된다.
current power와 initial power를 비교해서 어느쪽이 높은지 결졍.
power가 낮아지면 하얀색, 높아지면 빨간색으로 서서히 변한다.
'프로그래밍 > Unreal' 카테고리의 다른 글
[12]Battery Collector_UMG 활성화 (0) | 2017.05.11 |
---|---|
[11]Battery Collector_particle추가 (0) | 2017.05.11 |
[09]Battery Collector _ power 일정수준씩 감소시키기 (0) | 2017.05.11 |
[08]Battery Collector_power추가, 아이템 획득시 power 증가시키기 (0) | 2017.05.07 |
[07]BatteryCollector_아이템습득 (0) | 2017.05.06 |