|
Post by weltkatze on May 3, 2020 4:57:38 GMT
What would be the best way to integrate a push/pull animation. I want to push a 3rd person Character a crate straight in one direction forward or backward.
my thoughts:
on the object to push create trigger on the push/pull side action key E moves "Free Locomotion" to new blend tree with push/pull walk animation ispush = true lock any other direction axis then forward / backward action key E releases to ispush = false back to "Free Locomotion"
is this all to complicated or is there an easier way I don't see
|
|
|
Post by komposite on May 3, 2020 6:13:15 GMT
It sounds like a step in the right direction, but I think you'll need to do something to change the transform of the object you're pushing/pulling to not rely on physics (especially for the pull).
|
|
lemcore
Junior vMember
vDude
Posts: 49
|
Post by lemcore on May 3, 2020 8:21:26 GMT
I can tell how I did a draggable box 1) made the movement type "Strafe" in the animator (Free locomotion is not suitable for this mechanics since there is a rotation method there) 2) made a script to synchronize the positions of the character and the object that we are moving (or the object that we are moving, you can make it a child for the duration of the action) 3) you can start it all through the Generic action trigger or write your own trigger script for this action 4) add Inverse Kinematics (IKGoal) to this and everything will look great
|
|
|
Post by deerhwy on May 3, 2020 16:45:09 GMT
I can tell how I did a draggable box 1) made the movement type "Strafe" in the animator (Free locomotion is not suitable for this mechanics since there is a rotation method there) 2) made a script to synchronize the positions of the character and the object that we are moving (or the object that we are moving, you can make it a child for the duration of the action) 3) you can start it all through the Generic action trigger or write your own trigger script for this action 4) add Inverse Kinematics (IKGoal) to this and everything will look great Just did exactly this ^^ except, instead of making the movement type Strafe, you can also disable rotation via the script. I think either works. Lemcore, have you been able to get it so the player won't rotate with the camera? Every time I turn that off, he stops moving forward entirely.
|
|
lemcore
Junior vMember
vDude
Posts: 49
|
Post by lemcore on May 3, 2020 18:24:33 GMT
I can tell how I did a draggable box 1) made the movement type "Strafe" in the animator (Free locomotion is not suitable for this mechanics since there is a rotation method there) 2) made a script to synchronize the positions of the character and the object that we are moving (or the object that we are moving, you can make it a child for the duration of the action) 3) you can start it all through the Generic action trigger or write your own trigger script for this action 4) add Inverse Kinematics (IKGoal) to this and everything will look great Just did exactly this ^^ except, instead of making the movement type Strafe, you can also disable rotation via the script. I think either works. Lemcore, have you been able to get it so the player won't rotate with the camera? Every time I turn that off, he stops moving forward entirely. yes, I don’t use “Rotate with camera” in Strafe Locomotion, if you use this option you will need to turn it off
|
|
|
Post by deerhwy on May 3, 2020 19:30:21 GMT
Just did exactly this ^^ except, instead of making the movement type Strafe, you can also disable rotation via the script. I think either works. Lemcore, have you been able to get it so the player won't rotate with the camera? Every time I turn that off, he stops moving forward entirely. yes, I don’t use “Rotate with camera” in Strafe Locomotion, if you use this option you will need to turn it off Hmm every time I check "Ignore Camera Rotation" under the Input Manager, my character stops moving forward at all. How did you get around that? I already have "Rotate with Camera" unchecked by the camera rotation still seems to influence which way he pushes or drags the block. Also, you seem to have the IK dialled so I'm hoping to ask you a bit more about how you got there? This is the code I have right now to set the player's hand to my serialized target but it isn't working at all. Any help would be super appreciated. if (isGrabbing && Input.GetButton("Vertical") && Input.GetAxis("Vertical") > 0) { float reach = player.GetComponent<Animator>().GetFloat("RightHandReach"); player.GetComponent<Animator>().SetIKPosition(AvatarIKGoal.RightHand, IKTarget.position); player.GetComponent<Animator>().SetIKPositionWeight(AvatarIKGoal.RightHand, reach);
isPushing = true;
|
|
lemcore
Junior vMember
vDude
Posts: 49
|
Post by lemcore on May 3, 2020 21:09:05 GMT
Firstly why constantly use "GetComponent" if you can initialize at startup once and then use
void start() { animator = GetComponent<Animator>(); } IK is made like this:
void IK()
{
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, weightIK);
animator.SetIKRotationWeight(AvatarIKGoal.RightHand, weightIK);
animator.SetIKPosition(AvatarIKGoal.RightHand, IKTarget.position);
animator.SetIKRotation(AvatarIKGoal.RightHand, IKTarget.rotation);
}
|
|
lemcore
Junior vMember
vDude
Posts: 49
|
Post by lemcore on May 3, 2020 21:33:48 GMT
yes, I don’t use “Rotate with camera” in Strafe Locomotion, if you use this option you will need to turn it off Hmm every time I check "Ignore Camera Rotation" under the Input Manager, my character stops moving forward at all. How did you get around that? I already have "Rotate with Camera" unchecked by the camera rotation still seems to influence which way he pushes or drags the block. Also, you seem to have the IK dialled so I'm hoping to ask you a bit more about how you got there? This is the code I have right now to set the player's hand to my serialized target but it isn't working at all. Any help would be super appreciated. if (isGrabbing && Input.GetButton("Vertical") && Input.GetAxis("Vertical") > 0) { float reach = player.GetComponent<Animator>().GetFloat("RightHandReach"); player.GetComponent<Animator>().SetIKPosition(AvatarIKGoal.RightHand, IKTarget.position); player.GetComponent<Animator>().SetIKPositionWeight(AvatarIKGoal.RightHand, reach);
isPushing = true; P.S. it seems to me superfluous: Input.GetButton("Vertical")
|
|
|
Post by deerhwy on May 3, 2020 21:50:53 GMT
Thanks Lemcore. Good tip, I can see how it'd be more performant to define the animator on start only. However, i still can't get the IK working. I've set the weight to 1f for now. What am I missing? if (Input.GetButtonDown("Fire1") && isGrabbing) { player.animator.Play("GrabStart"); IK(); } private void IK() { player.animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1f); player.animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 1f); player.animator.SetIKPosition(AvatarIKGoal.RightHand, IKTarget.position); player.animator.SetIKRotation(AvatarIKGoal.RightHand, IKTarget.rotation); }
|
|
lemcore
Junior vMember
vDude
Posts: 49
|
Post by lemcore on May 3, 2020 22:38:17 GMT
You need OnAnimatorIK example:
void OnAnimatorIK() { IK(); }
|
|
|
Post by deerhwy on May 3, 2020 23:24:11 GMT
You need OnAnimatorIK example: void OnAnimatorIK() { IK(); } Hmm still having zero luck. I've tried putting "void OnAnimatorIK(int layerIndex){ " with the 4 IK lines on both the player and the object I'm interacting with but I've got nothing. I'll go watch some more tutorials on the subject - totally stuck here.
|
|
lemcore
Junior vMember
vDude
Posts: 49
|
Post by lemcore on May 3, 2020 23:34:36 GMT
You need OnAnimatorIK example: void OnAnimatorIK() { IK(); } Hmm still having zero luck. I've tried putting "void OnAnimatorIK(int layerIndex){ " with the 4 IK lines on both the player and the object I'm interacting with but I've got nothing. I'll go watch some more tutorials on the subject - totally stuck here. Code worked this is example; using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Invector.vCharacterController
{
public class script : MonoBehaviour
{
// protected Animator animator;
public vThirdPersonController player;
public Transform IKTarget;
public bool isGrabbing = true;
void Start()
{
player = GetComponent<vThirdPersonController>();
}
private void Update()
{
if (Input.GetButtonDown("Space") && isGrabbing)
{
// player.animator.Play("GrabStart");
OnAnimatorIK();
}
}
private void IK()
{
player.animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1f);
player.animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 1f);
player.animator.SetIKPosition(AvatarIKGoal.RightHand, IKTarget.position);
player.animator.SetIKRotation(AvatarIKGoal.RightHand, IKTarget.rotation);
}
void OnAnimatorIK()
{
IK();
}
}
}
|
|
|
Post by deerhwy on May 3, 2020 23:49:04 GMT
Hmm still having zero luck. I've tried putting "void OnAnimatorIK(int layerIndex){ " with the 4 IK lines on both the player and the object I'm interacting with but I've got nothing. I'll go watch some more tutorials on the subject - totally stuck here. Code worked this is example; Thanks! I'll give this a shot. Would this work if attached to the object I'm grabbing too or does it have to be attached to the player game object? Edit: I was able to make it work by enabling IK in the animator controller. How would I tell my avatar to only obey the X and Z axis of the IK target object? The code below seems like the Y axis is reaching for the player's Y position, as opposed to just the natural Y handposition: animator.SetIKPosition(AvatarIKGoal.LeftHand, new Vector3 (IKTarget.position.x, transform.position.y, IKTarget.position.z));
|
|
lemcore
Junior vMember
vDude
Posts: 49
|
Post by lemcore on May 4, 2020 11:53:33 GMT
Code worked this is example; Thanks! I'll give this a shot. Would this work if attached to the object I'm grabbing too or does it have to be attached to the player game object? Edit: I was able to make it work by enabling IK in the animator controller. How would I tell my avatar to only obey the X and Z axis of the IK target object? The code below seems like the Y axis is reaching for the player's Y position, as opposed to just the natural Y handposition: player.animator.SetIKPosition(AvatarIKGoal.RightHand, new Vector3(IKTarget.position.x, IKTarget.position.z)); animator.SetIKPosition(AvatarIKGoal.LeftHand, new Vector3 (IKTarget.position.x, transform.position.y, IKTarget.position.z)); no script should be on the character you were close to the goal player.animator.SetIKPosition(AvatarIKGoal.RightHand, new Vector3(IKTarget.position.x, IKTarget.position.z));
|
|
|
Post by deerhwy on May 4, 2020 15:21:20 GMT
no script should be on the character you were close to the goal player.animator.SetIKPosition(AvatarIKGoal.RightHand, new Vector3(IKTarget.position.x, IKTarget.position.z));
Hmm if I take out one of the 3 positions or remove it from the player script, it doesn't seem to work at all and produces an error if I take out both X and Y. Essentially I'm trying to make sure the pushing animation aligns with the edge of the box without altering the height or width on the box that the hands are placed at but I can't seem to get there
|
|