|
Post by ryannguyen on Mar 4, 2017 9:06:49 GMT
Hi! My name is Ryan. Nice too meet you. I have 2 problems.
Issue 1: When I was scaling my 3rd Person Controller(3PC) prefabs in the scene (including Third Person Controller component) bigger than 1 and in the V Melee Combat Input (script) I was:
+ Changed Gameplay Input Style to Click And Move + Changed Click Move Layer name to the same layer that I've setup on my floor mesh
My 3PC was keep moving around when he reached the target mouse position (but I want him to stop like in the original Click And Move feature)
Issue 2: I was writing a Play Maker custom action so my Character can move to a particular position setup and call by a Play Maker action
var dir = (pos - oldPos).normalized; if (!NearPoint(pos, oldPos)) cc.input = new Vector2(dir.x, dir.z); else { cc.input = Vector2.Lerp(cc.input, Vector3.zero, 20 * Time.deltaTime); everyFrame = false; }
But when NearPoint is true my Character continue moving without no reason. How can I stop him?
Code in my PlayMaker OnUpdate() function
public override void OnUpdate() { if (everyFrame) MoveToPosition(); else { //cc.input = Vector3.zero; cc.lockMovement = true; return; } } Thanks!.
|
|
|
Post by sickscore on Mar 4, 2017 9:24:22 GMT
Hi! My name is Ryan. Nice too meet you. I have 2 problems. Issue 1: When I was scaling my 3rd Person Controller(3PC) prefabs in the scene (including Third Person Controller component) bigger than 1 and in the V Melee Combat Input (script) I was: + Changed Gameplay Input Style to Click And Move+ Changed Click Move Layer name to the same layer that I've setup on my floor mesh My 3PC was keep moving around when he reached the target mouse position (but I want him to stop like in the original Click And Move feature) Issue 2:I was writing a Play Maker custom action so my Character can move to a particular position setup and call by a Play Maker action var dir = (pos - oldPos).normalized; if (!NearPoint(pos, oldPos)) cc.input = new Vector2(dir.x, dir.z); else { cc.input = Vector2.Lerp(cc.input, Vector3.zero, 20 * Time.deltaTime); everyFrame = false; }
But when NearPoint is true my Character continue moving without no reason. How can I stop him? Code in my PlayMaker OnUpdate() function public override void OnUpdate() { if (everyFrame) MoveToPosition(); else { //cc.input = Vector3.zero; cc.lockMovement = true; return; } } Thanks!. Hey ryan, for issue 1: Don't scale your character after creating it with the manager. Change scale in the import settings of the character. for issue 2: In your vThirdPersonAnimator line 154: animator.SetFloat("InputVertical", !stopMove || !lockMovement ? speed : 0f, 0.25f, Time.deltaTime); There should be a "!" infront of "lockMovement". You can also lerp down the speed variable, then it looks a bit more natural. Cheers, sickscore
|
|
|
Post by ryannguyen on Mar 4, 2017 11:33:08 GMT
Hey ryan, for issue 1: Don't scale your character after creating it with the manager. Change scale in the import settings of the character. for issue 2: In your vThirdPersonAnimator line 154: animator.SetFloat("InputVertical", !stopMove || !lockMovement ? speed : 0f, 0.25f, Time.deltaTime); There should be a "!" infront of "lockMovement". You can also lerp down the speed variable, then it looks a bit more natural. Cheers, sickscore Thanks sickscore! You reply very quickly ! For issue 1: - I've changed scale Factor in the import settings of the character. - still not fix - I re-scaled .fbx, re-imported it to my project and created a new character with the manager - still not fix For issue 2: I've changed code in vThirdPersonAnimator line 154 Here is my PlayMaker action I made for PlayMaker invector comunity. Hope, I can fix it soon in order to help some people have the same problem like me. using Invector.CharacterController; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
namespace HutongGames.PlayMaker.Actions { [ActionCategory("Custom Action")] [Tooltip("Connect and move a Invector game object controller to a particular position")] public class InvectorMoveTo : FsmStateAction { protected vThirdPersonController cc;
[RequiredField] [Tooltip("Invector controller game object.")] public FsmOwnerDefault gameObject;
[ActionSection("Target Position")] [Tooltip("Move To a transform position.")] public FsmGameObject transformPosition;
[Tooltip("Position the GameObject will move to. If Transform Position is defined this is used as a local offset.")] public FsmVector3 vectorPosition;
[Tooltip("Whether to animate in local or world space.")] public Space space = Space.World;
[ActionSection("Events")] [UIHint(UIHint.FsmEvent)] public FsmEvent finishEvent;
[Tooltip("Repeat every frame.")] public bool everyFrame;
private GameObject go; // this game object private Vector3 oldPos;
public override void Reset() { transformPosition = new FsmGameObject { UseVariable = true }; vectorPosition = new FsmVector3 { UseVariable = true }; everyFrame = false; finishEvent = null; }
public override void OnEnter() { go = Fsm.GetOwnerDefaultTarget(gameObject); cc = go.GetComponent<vThirdPersonController>();
MoveToPosition(); if (!everyFrame) { Finish(); } }
public override void OnUpdate() { if (everyFrame) MoveToPosition(); else { cc.input = Vector3.zero; return; } }
private void MoveToPosition() { if (cc == null) return; cc.rotateByWorld = true; Vector3 pos = vectorPosition.IsNone ? Vector3.zero : vectorPosition.Value; if (!transformPosition.IsNone) if (transformPosition.Value) pos = (space == Space.World || go.transform.parent == null) ? transformPosition.Value.transform.position + pos : go.transform.parent.InverseTransformPoint(transformPosition.Value.transform.position) + pos; oldPos = (space == Space.World || go.transform.parent == null) ? go.transform.position : go.transform.parent.InverseTransformPoint(go.transform.position); var dir = (pos - oldPos).normalized; if (!NearPoint(pos, oldPos)) cc.input = new Vector2(dir.x, dir.z); else { cc.input = Vector2.Lerp(cc.input, Vector3.zero, 20 * Time.deltaTime); everyFrame = false; } } protected virtual bool NearPoint(Vector3 a, Vector3 b) { var _a = new Vector3(a.x, go.transform.position.y, a.z); var _b = new Vector3(b.x, go.transform.position.y, b.z); return Vector3.Distance(_a, _b) <= 0.5f; } } }
Sorry for the inconvenience! Thanks you! Still working!
|
|
|
Post by ryannguyen on Mar 5, 2017 6:57:32 GMT
Oh, I fix that, ready for a PlayMaker action
But I've one problem can I tell investors that I want to apply root motion (or update old position to newest position) to tell my character stand in the target position he reach?
For now, my character has just come back to the first position after he reaches the target position.
|
|
|
Post by Invector on Mar 5, 2017 15:43:51 GMT
I was actually doing some Adventure Creator integration last week and have to stop due the shooter progress, but I think we're going to similar paths regarding moving the character with the ClickAndMove method, we just had to create this 2 new methods. protected virtual void ClickAndMove() { var dir = (cursorPoint - transform.position).normalized; RaycastHit hit;
if (Input.GetMouseButton(0)) { if (Physics.Raycast(tpCamera.GetComponent<Camera>().ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, clickMoveLayer)) { if (onEnableCursor != null) { onEnableCursor(hit.point); } cursorPoint = hit.point; } }
if (!NearPoint(cursorPoint, transform.position)) cc.input = new Vector2(dir.x, dir.z); else { if (onDisableCursor != null) onDisableCursor();
cc.input = Vector2.Lerp(cc.input, Vector3.zero, 20 * Time.deltaTime); } }
public void SetTargetPosition(Vector3 value) { cursorPoint = value; var dir = (value - transform.position); cc.input = new Vector2(dir.x, dir.z); }
public void ClearTarget() { cc.input = Vector2.zero; } I'm actually looking forward to finish this integration, because I loved Adventure Creator tools! We will create a very cool bridge to several usefull methods and I think, could be a start for a Playmaker integration as well
|
|
|
Post by ryannguyen on Mar 5, 2017 21:41:40 GMT
Thanks you, admin!
OK, I fixed and finished a new PlayMaker action for Invector call "Invector Move To". This action can help PlayMaker dev interaction with Invector so that PM action can move character to a position. To use this action just simply:
+ Open vThirdPersonInput and change:
Vector3 cursorPoint; to
public Vector3 cursorPoint; and this is the action script
using Invector.CharacterController; using UnityEngine;
namespace HutongGames.PlayMaker.Actions { [ActionCategory("Custom Action")] [Tooltip("Connect and move a Invector game object controller to a particular position")] public class InvectorMoveTo : FsmStateAction { protected vThirdPersonInput ci;
[RequiredField] [CheckForComponent(typeof(vThirdPersonController))] [Tooltip("Invector controller game object.")] public FsmOwnerDefault gameObject;
[ActionSection("Target Position")] [Tooltip("Move To a transform position.")] public FsmGameObject transformPosition;
[Tooltip("Position the GameObject will move to. If Transform Position is defined this is used as a local offset.")] public FsmVector3 vectorPosition;
[Tooltip("Whether to animate in local or world space.")] public Space space = Space.World;
[ActionSection("Events")] [UIHint(UIHint.FsmEvent)] public FsmEvent finishEvent;
private GameObject go; // this game object private Vector3 oldPos; private Vector3 pos;
public override void Reset() { transformPosition = new FsmGameObject { UseVariable = true }; vectorPosition = new FsmVector3 { UseVariable = true }; finishEvent = null; }
public override void OnEnter() { MoveToPosition(); }
public override void OnLateUpdate() { if (NearPoint(pos, (space == Space.World || go.transform.parent == null) ? go.transform.position : go.transform.parent.InverseTransformPoint(go.transform.position))) { if (finishEvent != null) { Fsm.Event(finishEvent); } Finish(); } } private void MoveToPosition() { go = Fsm.GetOwnerDefaultTarget(gameObject); ci = go.GetComponent<vThirdPersonInput>(); if (ci == null) return; pos = vectorPosition.IsNone ? Vector3.zero : vectorPosition.Value; if (!transformPosition.IsNone) if (transformPosition.Value) pos = (space == Space.World || go.transform.parent == null) ? transformPosition.Value.transform.position + pos : go.transform.parent.InverseTransformPoint(transformPosition.Value.transform.position) + pos;
ci.cursorPoint = pos; } protected virtual bool NearPoint(Vector3 a, Vector3 b) { var _a = new Vector3(a.x, go.transform.position.y, a.z); var _b = new Vector3(b.x, go.transform.position.y, b.z); return Vector3.Distance(_a, _b) <= 0.5f; } } }
The second problem was solved!
|
|