Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Why is this happening?

A topic by Wolfie created Apr 02, 2021 Views: 351 Replies: 7
Viewing posts 1 to 8
Submitted

I wrote this script to follow the player, but it just moves upward forever.


using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class follow : MonoBehaviour

{

    public GameObject Player;

    // Start is called before the first frame update

    void Start()

    {

        

    }

    // Update is called once per frame

    void Update()

    {

        Vector3 Location = Player.transform.position;

        transform.Translate(Location*Time.deltaTime);

        Debug.Log(Location * Time.deltaTime);

    }

}

(1 edit)

Try subtracting transform.position from the player transform position like this:

Vector3 Location = Player.transform.position - transform.position

Submitted

it just flies toward 0,0,0

Isn't there a function in Unity called MoveTowards?

Submitted

it did work for a bit, but when i created a canvas they started to fly to the spawner and delete themselves

Submitted

nvm fixed it with a reimport

Submitted (1 edit)

use the namespace

Using UnityEngine.AI


Then download a navmesh make an empty object and add a component called navmesh surface i think


And add a navmesh agent component to the AI

Then get the players transform

Make a float inSightRange


N then if player.transform.position - in sightrange  oh im really sorrh but i cant remember the math to check if player is in sight range 

But if he is 

Since u have the using UnityEngineAI

agent.destination(player.transform)


This is a very simple variation that im typing from my phone rn so there might be some errors

Submitted

i fixed it, plus the game is 2D so navmesh wont work