Navigate to the Solution Explorer in the Visual Studio and open the FPSCharacter.cpp class implementation file. Function that handles firing projectiles. UPROPERTY(VisibleDefaultsOnly, Category = Mesh) First-person mesh (arms), visible only to the owning player. Clears jump flag when key is released. Handles input for moving right and left. Handles input for moving forward and backward. Virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override Sets default values for this character's properties All Rights Reserved.Ĭlass FPSPROJECT_API AFPSCharacter : public ACharacter Navigate to the Solution Explorer in the Visual Studio and open the FPSCharacter.h class header file.Īdd the following function declaration in FPSCharacter.h, under public access specifier:įPSCharacter.h // Copyright Epic Games, Inc. ProjectileMovementComponent->Velocity = ShootDirection * ProjectileMovementComponent->InitialSpeed Void AFPSProjectile::FireInDirection(const FVector& ShootDirection) Void FireInDirection(const FVector& ShootDirection) Īdd the following function definition to FPSProjectile.cpp: Function that initializes the projectile's velocity in the shoot direction. Setting the Projectile's Initial VelocityĪdd the following function declaration in FPSProjectile.h, under public access specifier: ProjectileMovementComponent->ProjectileGravityScale = 0.0f ProjectileMovementComponent->Bounciness = 0.3f ProjectileMovementComponent->bShouldBounce = true ProjectileMovementComponent->bRotationFollowsVelocity = true ProjectileMovementComponent->MaxSpeed = 3000.0f ProjectileMovementComponent->InitialSpeed = 3000.0f ProjectileMovementComponent->SetUpdatedComponent(CollisionComponent) ProjectileMovementComponent = CreateDefaultSubobject(TEXT("ProjectileMovementComponent")) Use this component to drive this projectile's movement. Navigate to the FPSProjectile.cpp class implementation file.Īdd the following lines of code to the AFPSProjectile constructor in FPSProjectile.cpp: UProjectileMovementComponent* ProjectileMovementComponent UPROPERTY(VisibleAnywhere, Category = Movement) UPROPERTY(VisibleDefaultsOnly, Category = Projectile) Virtual void Tick( float DeltaTime ) override Sets default values for this actor's properties #include "GameFramework/ProjectileMovementComponent.h"Ĭlass FPSPROJECT_API AFPSProjectile : public AActor Navigate to the FPSProjectile.h class header file.Īdd the ProjectileMovementComponent header file.įPSProjectile.h // Copyright Epic Games, Inc. Void AFPSProjectile::Tick( float DeltaTime ) Called when the game starts or when spawned Set the root component to be the collision component. Use a sphere as a simple collision representation.ĬollisionComponent = CreateDefaultSubobject(TEXT("SphereComponent")) ĬollisionComponent->InitSphereRadius(15.0f) RootComponent = CreateDefaultSubobject(TEXT("ProjectileSceneComponent")) You can turn this off to improve performance if you don't need it. Set this actor to call Tick() every frame. Your input settings should now look like the following:įPSProjectile.cpp // Copyright Epic Games, Inc. In the dropdown menu, select Left Mouse Button from the Mouse dropdown list. Type Fire into the text field that appears. Under the Bindings on the right side, click the (+) sign next to Action Mappings.Ĭlick the arrow to the left of Action Mappings. Under the Engine heading on the left side of the Project Settings tab, click Input. During this step, you are going to add input and create a new code class for our projectile.Ĭlick the Edit in the Main menu panel, select Project Settings. You are going to program a simple grenade-like projectile to shoot from the center of the screen and fly until it collides with the world. Now that you have set up your character, it's time to implement a projectile weapon. Get Your Projectiles to Interact with the Worldģ.3 - Setting Up Projectile Collision and Lifetimeģ.4 - Getting Projectiles to Interact with the World The purpose of this section is to show you how to implement projectiles for your First Person Shooter game.īy the end of this section of the tutorial, you'll be able to: This is what you'll see at the end of this section.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |