vel
New vMember
Posts: 9
|
Post by vel on Dec 1, 2018 16:10:13 GMT
Hi! I was wondering if there was a way to remove the clicking parts of the controller, so I end up with a public target object that I can move around and have the character follow it the same way it follows the cursor when the click button is being held.
|
|
|
Post by Invector on Dec 3, 2018 14:03:31 GMT
I'm not sure what you mean, you want the character to always follow the target, even without clicking? You can switch/customize the cursor sprite in the gameObject ClickToMoveCursor
|
|
vel
New vMember
Posts: 9
|
Post by vel on Dec 4, 2018 0:01:46 GMT
I cant's switch the cursor sprite on because it's being controlled by the script, the only way for it to appear is by clicking somewhere. What I wanted is to remove the need to click for the target to appear, so the target is always active.
That way, for example, i could put it on a dog's tail and have the character follow the animal wherever it goes, without input from the player.
|
|
|
Post by Invector on Dec 4, 2018 1:25:29 GMT
Well... simple open the script and comment the part that disables the object
public void Disable() { //cursorObject.SetActive(false); //enableCursor = false; }
|
|
vel
New vMember
Posts: 9
|
Post by vel on Dec 4, 2018 2:18:31 GMT
That only makes the cursor object visible, but the character still follows the position created when i click anywhere on the ground.
Is there a way to make the character follow the position of an empty game object, instead of a point created when I click the ground?
I want to be able to have a "target" object in the scene that the character can follow if I just grab it and move it around in the scene view.
An example would be having an empty gameobject as the child of a dog that runs forward. I'd like that gameobject's position to be the destination point for the character, so if the dog runs, the character will follow it automatically.
So, in short, I'm asking for a way to completely ignore the click input(or any input), and have the character from the demo scene just follow another game object's position.
|
|
|
Post by Invector on Dec 4, 2018 13:24:21 GMT
I see... that sounds more like a AI behavior than a Character Controller Have you tried using the AI with a target? it will do exactly what you want
|
|
vel
New vMember
Posts: 9
|
Post by vel on Dec 4, 2018 16:14:08 GMT
Yes, it is the AI behavior that the character in the scene already has (the one that makes him follow the place where I click on the ground). As the AI "follow behavior" is already perfectly implemented on the demo scene, I don't see AI as being part of the issue. What I'm asking has more to do with how the character's target position is generated:
1. I'd like to remove the need for mouse input in order to create a target position for the character. 2. Instead, I'd like to set the target position to a public gameobject's transform.
Is that possible by commenting certain lines of the code and replacing the definition of the target position(or the SetTargetPosition method?)?
|
|
|
Post by Invector on Dec 4, 2018 16:31:57 GMT
Sure, you can create a public variable transform and use the method MoveCharacter(yourTransform) from the vThirdPersonInput
|
|
vel
New vMember
Posts: 9
|
Post by vel on Dec 4, 2018 19:07:26 GMT
Ok, i was looking into the script and I couldn't make much sense of it (I'm sorry, I'm not a programmer). So, i found these:
public virtual void MoveCharacter(Vector3 position, bool rotateToDirection = true) { var dir = position - transform.position; var targetDir = cc.isStrafing ? transform.InverseTransformDirection(dir).normalized : dir.normalized; cc.input.x = targetDir.x; cc.input.y = targetDir.z;
if (!keepDirection) oldInput = cc.input;
if (rotateToDirection && cc.isStrafing) { targetDir.y = 0; cc.RotateToDirection(dir); Debug.DrawRay(transform.position, dir * 10f, Color.blue); } else if (rotateToDirection) { targetDir.y = 0; cc.targetDirection = targetDir; } }
public virtual void MoveCharacter(Transform _transform, bool rotateToDirection = true) { MoveCharacter(_transform.position, rotateToDirection); }
protected virtual void MoveCharacter() { // gets input from mobile cc.input.x = horizontalInput.GetAxis(); cc.input.y = verticallInput.GetAxis(); // update oldInput to compare with current Input if keepDirection is true if (!keepDirection) oldInput = cc.input; }
What could i comment in order to block input and where should i define the target as a public game object?
|
|
vel
New vMember
Posts: 9
|
Post by vel on Dec 5, 2018 21:23:36 GMT
I've been trying to change some things on the code without success. I'll post the most accurate description of the issue in the hopes someone knows the answer: This is the isometric click-to-move demo scene as it is by default. Here you can see that the character moves by following the point on the ground where my mouse button is being held. The way the character follows is perfect. It vaults, climbs and rotates perfectly. And this is an example of what I'd like to do: In this case, the character is following the red sphere. This sphere is being controlled by me using WASD. Wherever the sphere is, the character follows, just as it followed my cursor as long as i kept the button pressed on the previous GIF. In that script, my character has a public game object as its target, so i just dragged the sphere into the inspector field and now he follows the sphere. So, i'd like a behavior like the second example, but i want to use the invector character, as it turns around, moves, climbs and vaults automatically as it is in the isometric demo scene. What changes could i make to the script in order to make the character from the isometric demo scene follow a public object's position like the second GIF? I'm very grateful for any help or advice you can give!
|
|
|
Post by Invector on Dec 6, 2018 13:47:36 GMT
You will need to use a vThirdPersonInput instead of the vClickToMoveInput, and comment it out the method InputHandle (so you won't be able to control the character) and instead call the method "MoveCharacter(myCustomTarget, true);" being myCustomTarget a "public Transform myCustomTarget" that you will assign your gameObject to follow in the inspector.
|
|
vel
New vMember
Posts: 9
|
Post by vel on Dec 6, 2018 14:01:42 GMT
Thank you so much! i'll try this right away!
|
|
vel
New vMember
Posts: 9
|
Post by vel on Dec 6, 2018 17:22:09 GMT
Ok, so far so good! The character followed it perfectly.
I tried duplicating the vThirdPersonInput and renaming it to "vThirdPersonInputFollow"(I need both versions for different characters), but the follower character's script always reverts back to the default vThirdPersonInput. This also happens with the camera's target, it always looks for the character when i press play, even if i set another object as it's target.
Is there any way to override this behavior?
Also, i remember that when i used NavMesh agents, once the agent reached it's destination, it stopped. In this case, once the character reaches the target location, it circles around the target forever. Where could I add a line that stops it's movement once the target location has been reached(without having to destroy myCustomTarget object)?
As of now, i was thinking of making a boolean that allows the character to enter the MoveCharacter method, and enable/disable it depending on the distance between the character and it's target position. Something like:
public bool letCharacterMove;
void Update() { if (Vector3.Distance(destination, myCustomTarget.position) > 0.2f) { destination = myCustomTarget.position; agent.destination = destination;
letCharacterMove = true; } if (Vector3.Distance(destination, myCustomTarget.position) == 0) {
letCharacterMove = false; } }
(At this point, I might be getting too picky with the locomotion's features. It's perfectly fine to say "you need a programmer" if the answer to these questions are way too complex for a beginner like me.)
|
|