Could I get some help with this hookshot function?

I’ve been working on a function that takes in where you’re looking and moves you in that direction, like a hookshot, which uses the third person code as a start. I think I have a good start here but in editor it does nothing.

code in sCharacter.cpp

void AsCharacter::hookaim(float value)
{
	if ( (Controller != NULL) && (value != 0.0f))
	{
		//find which way you we're looking
		const FRotator Rotation = Controller->GetControlRotation();
		const FRotator MyRotation(Rotation.Roll, Rotation.Yaw, Rotation.Pitch);
		//Move in that direction
		const FVector Direction = FRotationMatrix(MyRotation).GetUnitAxis(EAxis::X);
		//need this ^ to take all axis
		AddMovementInput(Direction, value);
	}
}

This all compiles btw.

First of I’m not sure how to get FRotaionMatrix(MyRotation) to get X,Y and Z instead of just X, and plugged X in just to see if it works, it doesn’t. I have set the function name in the editor project input settings to activate when left click is pressed.

Any ideas?

I believe the function APawn::AddMovementInput is used purely for ground movement. You would need to do something similar to the jump code in ACharacter and UCharacterMovementComponent in order for your character to move through the air. In other words, you’d have to set the movement mode to falling and set the velocity directly.

First off, you won’t be able to move vertically via AddMovementInput while your movement mode is “Falling” and lateral movement will be limited by your air control values. Setting the movement mode to “Flying” will allow you to do this, but it will also disable gravity which may or may not be acceptable. As Redshft mentioned, you can set the velocity directly as well, but that will not work in a networked environment since you’ll be working around the input system. This may or may not be acceptable. If you need more specific behavior then you can create a custom movement mode in your movement component.

As far as your rotation issue goes, I think what you’re probably looking for is GetForwardVector(). You can call this on any scene component, probably the camera would be your best bet here. However, I see that the method you are using ( FRotationMatrix(MyRotation).GetUnitAxis(EAxis::X); ) is what KismetMathLibrary does to find a forward vector. I suspect Controller->GetControlRotation(); might not be what you’re expecting it to be, it might not be reliable.