When we initialize any class in the unreal engine we want to setup the 'CollisionComp', 'MovementComp' and other useful information like does this actor tick or not?
CollisionComp defines how the class will interact with the game world. The most important functions of the collision component are 'InitSphereRadius' and 'SetCollisionResponseToChannel'.
The 'InitSphereRadius' creates a capsule around the class which handles all the collision. Without this there would be no collision for the class. Creating a collision capsule also improves performance since it simplifies collision detection.
The 'SetCollisionResponseToChannel' allows you to define how this class will interact with other objects. For example you could set
CollisionComp->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Ignore);This will allow the class to travel through walls and other static meshes. As you can image you can get create with all the different collision response channels.
MovementComp defines all the aspects of the classes movement. There are many cool functions that allow you to set things such as: InitialSpeed, MaxSpeed, ProjectileGravityScale, etc.
if (IsPoisoned == true){Health -= 10.0f;}
'PostInitializeComponents' is a function that runs once the class is spawned in game. In our example of the grenade, that would be once the player presses the key to start to throw a grenade. Then we are going to do three things in our 'PostInitializeComponents'.
First we are going to set the life span of the grenade. This is going to be when the grenade explodes and is then subsequently removed from the game. We set the life span to 4 seconds, which is standard for a grenade's life.
Next we are going to tell the grenade who created him. This will be useful for obtaining statistical information, like whose grenade killed the enemy. We could also do interesting things like player perks that increase the damage of grenades.
.png)
.png)
%2B-%2BCopy.png)
.png)
%2B-%2BCopy.png)
.png)
No comments :
Post a Comment