I cannot figure out how do i use AddImpulse. Iam trying to make a simple roll a ball game but it keeps crashing when i press play. What am i doing wrong?
This is my cpp file:
// Fill out your copyright notice in the Description page of Project Settings.
#include "RollaBall.h"
#include "BallPlayer.h"
// Sets default values
ABallPlayer::ABallPlayer()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
USphereComponent* sphere = FindComponentByClass<USphereComponent>();
}
//Input function
void ABallPlayer::Move(float AxisUpDown, float AxisLeftRight)
{
Movementinput.Y = AxisUpDown;
Movementinput.X = AxisLeftRight;
sphere->AddImpulse(FVector(Movementinput.X, Movementinput.Y,0.0f));
}
// Called when the game starts or when spawned
void ABallPlayer::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ABallPlayer::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
Move(Movementinput.Y,Movementinput.X);
}
// Called to bind functionality to input
void ABallPlayer::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
}