Download

Control Fixed Player Animation Via Mouse Movement?

Hoping someone could point me in the right direction here or at least a starting point. My game play is very similar to Golf or Disc Golf. The character spawns at a fixed starting point and the player can then “Aim” left/right via arrow keys. I have a basic idle animation playing during this pre-shot period. Once aim is adjusted the player then left clicks with the mouse to initiate the start of the swing. This is where I’m having trouble. I want to real time sync a swing animation I have to the motion of the player’s mouse movement input. So immediately as the player drags/pulls their mouse back the animation frames play based on mouse movement. Pretty much exactly how you can scrub an animation in Persona.

Ideally, I would want to use separate Backswing and Downswing animations blended. The power of the swing would be dictated by how far back the player pulled the mouse back up to a max position based on end of the Backswing animation. Then the player would push the mouse in the opposite direction for the Downswing animation movement. Just looking to get a basic setup at this point but eventually I would like to include a calculation that factors the rate or pace of motion during the Downswing as an additional impact on the total overall power output. My hope is that this can act as a way to implement an extra level of feel to the swing motion.

So in essence the game play is quite simple. Spawn at defined start point, aim, left click and then swing mouse to hit shot, auto-advance character to position where the ball came to rest from previous shot and the play next shot until finally putting ball in target to finish the first level or in golf terms it would be “hole”.

Thanks,

Uvhausen

Bumping thread since it’s been almost a week.

FYI - I was able to successfully code a working prototype of a golf swing in Unity a couple years ago. Below is C# code after player initiates the swing with a simple mouse input click for reference which I hope might help someone to provide some info on how to achieve this in UE4 blueprints. I can upload a playable example of the below code as well if that would be helpful.

================================================================================================================
using UnityEngine;
using System.Collections;

public class golfswing : MonoBehaviour {

// Use this for initialization
void Start() {

	animation "Backswing2"].layer = 1;
	animation "Downswing2"].layer = 2;

	animation"Backswing2"].speed = 0;
	animation"Downswing2"].speed = 0;
	
}

Vector3 lastMouseCoordinate = Vector3.zero;

// Update is called once per frame	
void Update(){
	// First we find out how much it has moved, by comparing it with the stored coordinate.
	Vector3 mouseDelta = Input.mousePosition - lastMouseCoordinate;

	// Then we check if it has moved to the right.
	if(mouseDelta.x >0) {
	// Assuming a positive value is to the right.
		animation.Play ("Backswing2");}	

	// Then we check if it has moved to the left.
       else if (mouseDelta.x < 0) {
	// Assuming a negative value is to the left.
		animation.CrossFade ("Downswing2");	}
		
	// Then we store our mousePosition so that we can check it again next frame.
		lastMouseCoordinate = Input.mousePosition;

		animation "Backswing2"].normalizedTime = 3.0f * Input.mousePosition.x / Screen.width - 1;	
		animation "Downswing2"].normalizedTime = -(1.4f * Input.mousePosition.x / Screen.width - 1);
		
}

}