-1

I'm looking for c# script. And once i'm creating the new automatic walking script i need to drag it to the ThirdPersonController ?

Like patrloing. I give two values of two points and the character will go between the two points automatic and if there is an object in the path it will climbe over it or if it's mor logic will stop the patrol or go aorund it.

But at first i'm not sure how just to make it move automatic between two points.

Today i'm using in my ThirdPersonController in Inspector in the Animator part: ThirdPersonAnimatorController

And in the Third Person User Control (Script) i'm using the: ThirdPersonUserControl

The script is from the unity.

TheLost Lostit
  • 505
  • 6
  • 28
  • For simply moving between two points, take a look at [link](https://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html). For avoiding obstacles, you'll want to read up on pathfinding algorithms (for example: A*) – Coffee Boat Jul 22 '16 at 21:39
  • @Rimply I looked at the example in the link. I created a new script file added the code and then dragged the script to the ThirdPersonController. Then in the Insepctor i set the Target: ThirdPersonController (Transofrm) and the speed to 5. But the character is not moving. And if i set in the target to Main Camera then the character move backward stutter jump crunch strange. – TheLost Lostit Jul 22 '16 at 21:44
  • Regarding this last comment, you might be better to ask over at the Unity forums –  Jul 22 '16 at 22:00

2 Answers2

0

Example:

public GameObject thirdPerson; // you third person GameObject
public int oldPosition = 5; // start (old) point
public int newPosition = 10; // new point

void Update()
{ 
    if (oldPosition <= newPosition)
    {
        oldPosition += Time.deltaTime;
    }
    thirdPerson.transform.position = new Vector3(oldPosition, 0, 0);
}
ARTAGE
  • 379
  • 2
  • 4
  • 14
0

You need to create a Navmesh agent Create Navmesh Agent. This will allow a character to automatically walk around objects, and jump over obstacles.

Do a little bit of research before starting, and write down what you need your character to do first. Your scene can be updated with a new navmesh, as you bake which objects are walkable, must be avoided, and which can be jumped over.

If this seems like too big of a task, there are simple AI scripts available from the unity asset store for free that will do what you want.

Once you have your working navmesh here is a link to moving it between patrol points. Navmesh Agent Patrol.