|
Post by glaurung on Mar 14, 2017 21:05:13 GMT
Hi, I am enjoying working and playing with the Melee system, but I got stuck here for some hours already: - The horizontal input is mirrored when the camera is 2.5D and I lock on to enemies on my player's left hand side.
So, if I lock on to an enemy at the left of the player and want to get closer, it actually walks away from the enemy.
When the enemy is on the right hand side it all works fine, it is only when the enemy is on the left hand side.
I noticed that there's a variable called " Inverse Input Direction" in vMeleeCombatInput, but that's all: there seems to be no code using it. I am using some code with InverseTransformPoint in the vThirdPersonCamera class so to tell if the enemy is left or right, but afterwards I find it hard to pass a variable to vThirdPersonInput. void WhatSide (Transform enemy) { Vector3 position = enemy.InverseTransformPoint(target.position);
if (position.x > 0) print("Enemy is Left");
else print("Enemy is Right"); } Then, if enemy is on the left, I guess it would be easy to just multiply by -1 the horizontal input in vThirdPersonInput, something like this: protected virtual void ControllerInput() {
if (EnemyOnTheLeft) { // gets input from mobile cc.input.x = -horizontalInput.GetAxis(); } else cc.input.x = horizontalInput.GetAxis(); // update oldInput to compare with current Input if keepDirection if (!keepDirection) oldInput = cc.input; } Again, I am stuck telling the ControllerInput: "Hey, mirror that horizontal input for a moment". How would you guys mirror the Horizontal axis momentarily? Thanks!
|
|
|
Post by jorg3n3gr3iros on Mar 21, 2017 17:38:46 GMT
Hey man! Tiago and I find a solution, at the vThirdPersonInput change the method ControllerInput() to this... protected virtual void ControllerInput() { if (!tpCamera.lockTarget || cc.isRolling) { cc.input.x = horizontalInput.GetAxis(); cc.input.y = verticallInput.GetAxis(); } else { var dir = new Vector3(horizontalInput.GetAxis(), 0, verticallInput.GetAxis()); dir = Quaternion.LookRotation(tpCamera.transform.forward) * transform.InverseTransformDirection(dir); cc.input.x = dir.x; cc.input.y = dir.z; }
// update oldInput to compare with current Input if keepDirection if (!keepDirection) oldInput = cc.input; } You don't need to know what side the enemy is, the code will convert the direction using Camera.Forward and InverseTransformDirection
|
|
|
Post by glaurung on Mar 26, 2017 13:35:45 GMT
Thanks jorg3n3gr3iros!!!
Just tried and works like a charm!
I really appreciate your help and Tiago's!
|
|
|
Post by glaurung on Dec 4, 2017 22:32:04 GMT
If by any chance anyone is trying to make the player move relative to the locked-on enemy with Fixed Camera settings, then this is how I managed to do it with the newest Invector Code.
Make sure vThirdPersonInput > MoveCharacter() looks like below:
protected virtual void MoveCharacter() { if (tpCamera == null) return;
if (!tpCamera.lockTarget || cc.isRolling) { cc.input.x = horizontalInput.GetAxis(); cc.input.y = verticallInput.GetAxis(); } else { var dir = new Vector3(horizontalInput.GetAxis(), 0, verticallInput.GetAxis()); dir = Quaternion.LookRotation(tpCamera.transform.forward) * transform.InverseTransformDirection(dir); cc.input.x = dir.x; cc.input.y = dir.z; }
// update oldInput to compare with current Input if keepDirection if (!keepDirection) oldInput = cc.input; }
|
|