#AI movement

1 messages ยท Page 1 of 1 (latest)

haughty basin
hexed frost
#

the capsule will need a NavMeshAgent component

haughty basin
#

check

hexed frost
#

and you'll need a script to set the navmeshagent's destination variable

naive coral
#

there is a method i think

hexed frost
#

I think it's destination

haughty basin
#

leme explain what im doin here

#

so its a static turret defense game

#

that black spot on the hill, is the player

naive coral
haughty basin
#

just so yall know

naive coral
#

to make the navmesh go to a certain position

haughty basin
#

alright

#

is that a method?

naive coral
#

u need a navmeshagent

haughty basin
#

i have it

haughty basin
#

i need to code it in?

hexed frost
#

everything you can do with a navmeshagent is at my link ๐Ÿ˜›

naive coral
haughty basin
hexed frost
#

yeah, you'll need to make an 'enemymovement' script

haughty basin
#

idc really, just curious

#

its funny

naive coral
hexed frost
naive coral
#

everyone does smth

#

i dont rlly do anything ngl

haughty basin
#

me neither

naive coral
#

maybe

haughty basin
#

does the method need to be called in start? or update?

hexed frost
#

I do the dashes in my sentences for punctuation too - no idea where that came from

naive coral
#

you want it to happen every frame

#

if it only happens for one frame then it wont move.

hexed frost
#

yeah, every frame, since your player position might change

naive coral
#

everything is in update pretty much

#

things that you only want to happen once

#

is in start or awake

haughty basin
#

the players position does not change, but the rotation does

naive coral
#

so getting a component

naive coral
#

one frame is one time

haughty basin
#

yeah

naive coral
#

its only for like what is it 1/60th of a second

haughty basin
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class enemyMovement : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        SetDestination(506.6,75.8,652.6);
    }
}
naive coral
#

if you are at 60 fps

haughty basin
#

i know i did this wrong

naive coral
#

is it just me or do dictionaries suck

haughty basin
#

they do.

#

i cant figure this shit out

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class enemyMovement : MonoBehaviour
{
    NavMeshAgent agent;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        SetDestination(506.6,75.8,652.6);
    }
}

#

oh wait

#

Some scripts have compilation errors which may prevent obsolete API usages to get updated. Obsolete API updating will continue automatically after these errors get fixed.

#

it wont star tnow

#

is this even an error

hexed frost
#

compilation errors - I think for this one, it'd be something like "SetDestination doesn't want and doesn't like three floats, you gotta feed it a Vector3"

naive coral
#

u never reference it

haughty basin
naive coral
#

the navemshagent

naive coral
#

you have the component not the instance

haughty basin
#

oh

#

ffs

#

how do i get the instance?

naive coral
#

either reference via insepctor

#

or getcomponent those r the main ways

haughty basin
#

it takes 11 minutes to figure that out?

#

jesus

naive coral
#

it teaches u it

#

i dont wanna just give u the answer bc u wont learn

#

this video is very helpful

#

basically think of it this way

#

you got a token from a prize right?

#

the token says you can pick out a dog

#

is the token the dog you picked out? @haughty basin

haughty basin
#

no, the token is a the token?

naive coral
#

you use a token and then you get the dog with it

#

a dog is an instance

#

you can pick which instance to get with the token

#

the token is the navmesh variable

#

so basically you pick out which navmesh you want to assign to that variable

#

do u get it?

haughty basin
#

No not at all

naive coral
#

so...

#

i was given this exact lesson

#

do you know what a class is

haughty basin
#

what kind of class

naive coral
#

in programming

haughty basin
#

yeah, its a thing where you do stuff. it can be public, private, or protected.

naive coral
hexed frost
#

I'll give an example of my enemy movement script, it's pretty simple, just ignore all the animation stuff

naive coral
#

inside a class you pick the fur color

#

you pick how long the claws are

#

you pick the breed and color eyes

hexed frost
#
using UnityEngine.AI;
using UnityEngine;

public class enemyMovement : MonoBehaviour
{

    public Transform goal;
    public Animator m_animator;
    public float normalspeed;
    public bool isactive = false;
    public bool isattacking = false;
    public attacktriggerscript atkref;

    void Start()
    {
        m_animator.Play("bushmanidle");

    }
    void OnTriggerStay(Collider collider)
    {

        if (collider.tag == "Player")
        {
            m_animator.SetBool("aggro", true);
            NavMeshAgent agent = GetComponent<NavMeshAgent>();
            agent.destination = goal.position;

            isactive = true;
            if (!atkref.isattacking)
            {
                GetComponent<NavMeshAgent>().speed = normalspeed;
            }
        }
    }
    void OnTriggerExit(Collider col)
    {
        if (col.tag == "Player")
        {
            m_animator.SetBool("aggro", false);
            GetComponent<NavMeshAgent>().speed = 0;
            isactive = false;
            atkref.isattacking = false;

        }


    }
}```
naive coral
#

you following @haughty basin

haughty basin
#

Yeah

naive coral
haughty basin
#

GetComponent<NavMeshAgent>().speed = 0;

naive coral
#

its using the classes basically

#

so an instance of a class

#

is

#

lets say you create a class with black fur and blue eyes

haughty basin
#

thats an instance of cat

#

you can make another instance of cat with blue fur and black eyes

#

and so forth

naive coral
haughty basin
#

i know that stuff

naive coral
#

a class is an instruction

#

instance is a literal cat

#

if you have two instances of that class

#

you have two of those exact instances

#

basically you have a variable

#

you need to tell the variable the instance you want to manipulate

#

that is why u need getcomponent

#

you need to get the instance of the cat to change

#

so lets say you have instances cat 1 2 and 3

#

if you get instance 2

#

then you can use the variable that u store the instance in to change it

haughty basin
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class enemyMovement : MonoBehaviour
{
    NavMeshAgent agent;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        GetComponent<NavMeshAgent>();
        agent.SetDestination(506.6,75.8,652.6);
    }
}
naive coral
#

bc u only want to retrieve the instance once

#

you only need to tell the variable which cat it is once

haughty basin
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class enemyMovement : MonoBehaviour
{
    public NavMeshAgent agent;
    // Start is called before the first frame update
    void Start()
    {
        GetComponent<NavMeshAgent>();
    }

    // Update is called once per frame
    void Update()
    {
        
        agent.SetDestination(506.6,75.8,652.6);
    }
}

naive coral
hexed frost
#

using GetComponent this way will -only- work if this script is on the same gameobject as the navmeshagent

haughty basin
#

i did

#

i picked the navmeshagent

naive coral
#

in the inspector

#

you can drag in the correct instance

haughty basin
#

you're really losing me

naive coral
#

with get compoenent you wanna do agent = object.getcompoentn<navmeshagent>();

naive coral
haughty basin
#

I have it going.

hexed frost
haughty basin
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class enemyMovement : MonoBehaviour
{
    [SerializeField]
    public NavMeshAgent agent;
    // Start is called before the first frame update
    void Start()
    {
        agent = object.getcompoentn<navmeshagent>();
    }

    // Update is called once per frame
    void Update()
    {
        
        agent.SetDestination(506.6,75.8,652.6);
    }
}

hexed frost
#

then as long as enemymovement is on the same object as the navmeshagent, that should get the reference

naive coral
#

Think about it logically

#

You are trying to retrieve the instance

#

You donโ€™t need to do it twice

hexed frost
#

getcomphjxbasibckjsbhnkj is not going to work

#

its GetComponent

naive coral
haughty basin
#

sorry about that

hexed frost
#

๐Ÿ˜„

haughty basin
hexed frost
#

it's a different way to reference it

#

normally, the easiest way to define a variable, is just to drag the gameobject with the relevant component into an inspector window

#

but in this case, I think this is an even eeeeasier way

naive coral
haughty basin
#

there is nothing in the inspector

naive coral
#

*u

haughty basin
#

yeah

hexed frost
#

you'd have to add serializefield, but you don't need to do that at all

#

GetComponent, without an operator, references the parent gameobject

haughty basin
#

alright i am seriously confused

#

do i use getComponent

#

or serializefield

naive coral
#

Either

haughty basin
#

but i can't have both???

naive coral
#

Nope

#

You are trying to retrieve the instance. Why would u need both

haughty basin
#

agent = object.GetComponent<NavMeshAgent>();

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class enemyMovement : MonoBehaviour
{
    [SerializeField]
    public NavMeshAgent agent;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
        agent.SetDestination(506.6,75.8,652.6);
    }
}

#

im getting the same eror

#

that "NavMeshAgent" can't be found

#

but i put in serializefield

hexed frost
#

serializefield just makes it so it shows up in inspector, to drag the object into

haughty basin
#

but there is nothing there

hexed frost
#

sounds like you had a bug I experienced today with compilation errors, add public int test;

#

up at the top, a new declaration

#

save, go back to unity

#

and it should be fixed

#

then you can remove the int test ๐Ÿ˜›

haughty basin
#

like this?

hexed frost
#

ye

#

save, go back to unity, should see both the int, and agent ๐Ÿ™‚

haughty basin
#

its still showing an error btw

#

The type or namespace name 'NavMeshAgent' could not be found

#

im reloading into unity

hexed frost
#

along with the other libraries.

#

each error is a clue to why its not working ๐Ÿ˜„

haughty basin
#

Yeah but the clue is in english, but its not really in english.

#

i don't understand a single error

#

why cant it just tell me what is wrong

#

instead of just saying big shit to make it look smarter

#

No overload for method 'SetDestination' takes 3 arguments

#

see what tf is this

hexed frost
#

thats the one I mentioned earlier

#

sec i'll quote myself

haughty basin
#
agent.SetDestination(Vector3(506.6,75.8,652.6));
hexed frost
#

nah, you'll need to make a new one - so on the line right before it:

#

Vector3 vec = new Vector3 (506.6, 75.8, 652.6);

#

and then change to agent.SetDestination(vec);

haughty basin
#
void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 vec = new Vector3(506.6,75.8,652.6);
        agent.SetDestination(vec);
    }
hexed frost
#

looks good

haughty basin
#

cant convert double to float

#

is there way that i can?

hexed frost
#

oshit it wants a double -_-

#

stand by ๐Ÿ˜›

#

oh wait no I know the problem

#

any fractional integer, like, a non-whole number, needs to have f after it

#

to define it as a float

#

not sure why

haughty basin
#

did it

#

oh theres another error.

#

but its from a different script

hexed frost
#

๐Ÿ˜„

haughty basin
#

i cant get the bullet from the guns to disappear if they hit something

hexed frost
#

gameObject.Destroy();

haughty basin
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class destroyBullet : MonoBehaviour
{
    void OnCollisionEnter(Collider coll) {
        if (coll.gameObject.name == "Terrain") {
            Destroy (gameObject);
        }
    }
}
hexed frost
#

oh wait yeah yours is actually correct mine is probably wrong

haughty basin
#

No overload for method 'Destroy' takes 0 arguments

#

that was with yours

hexed frost
#

yeah yours is right, mine is wrong -

haughty basin
#

here it just says..

hexed frost
#

I expect you are having collision issues

haughty basin
#

yes

hexed frost
#

Oh, thats the error?

haughty basin
#

yeah

hexed frost
#

change Collider to Collision

#

see, I was going to go off on a tangent about collision troubleshooting, but boom, there it is, in the error

haughty basin
#

they still don't destroy

hexed frost
#

no errors now?

haughty basin
#

yeah no errors

#

but they don't destroyh

#

im sending u a gif

hexed frost
#

small victories ๐Ÿ˜›

haughty basin
hexed frost
#

well it looks like we get to go into collision troubleshooting after all ๐Ÿ˜›

#

save and test ๐Ÿ™‚

haughty basin
#

nothing in console

hexed frost
#

move it to up before the if

haughty basin
#

nothing in console

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class destroyBullet : MonoBehaviour
{
    void OnCollisionEnter(Collision    coll) {
        Debug.Log(coll.gameObject.name);
        if (coll.gameObject.name == "Terrain") {
            
            Destroy (gameObject);
        }
    }
}
hexed frost
#

so, the bullet isn't colliding with anything, ever

#

does it have a collider?

haughty basin
#

a sphere collider, yes

hexed frost
#

a rigidbody?

haughty basin
#

yup

hexed frost
#

try making the bullets slower, could be that its too fast

#

there's special things you gotta do for super fast projectiles

#

unity default physics can't keep up

haughty basin
#

downed to 1500 from 3000

#

nothing in console

hexed frost
#

slower, slower

#

slow em right down, it's for a test, remember

#

not for.. gameplay finishing

haughty basin
#

1500 to 100

#

nothing in console

hexed frost
#

Oh wait

#

the bullet has a trigger collider.

#

use OnTriggerEnter instead

haughty basin
#

see thats what i did originally

hexed frost
#

and then you can change Collision back to Collider

haughty basin
#

we have come full circle

hexed frost
#

haha well, this problem was soooooo far down the list

haughty basin
#

finally

hexed frost
#

I didn't expect you to have it set to be a trigger collider ๐Ÿ˜›

haughty basin
#

i think i did that bc i want the enemies to die upon contact with the bullet

#

and my mind thought trigger

hexed frost
#

a trigger collider is basically just a collider that doesn't.. physically collide with stuff - it won't like, use unity physics to bounce off of other colliders

haughty basin
#

can i not make the bullets faster now?

hexed frost
#

but that doesn't matter in this case, it's perfect for registering collisions with terrain

#

well, try it out - remember there'll be a limit though

haughty basin
#

1500 doesnt work

hexed frost
#

if the bullet's collider passes completely through the terrain's collider within a frame, no collision will be registered

#

the trick I mentioned, involves shooting a raycast out from the front and back of the bullet, and adjusting the bullet's position appropriately when the ray touches a wall

haughty basin
#

1 sec

hexed frost
#

I gotta afk 20 mins or so

#

back in a bit

haughty basin
#

It works though, kinda

#

sometimes the bullets go through the gruond

#

but it doesnt have to be perfect

#

this is for a school project

hexed frost
#

you could have them destroy themselves on a timer

haughty basin
#

its not last second, but it kinda is

hexed frost
#

after like 20 secs

haughty basin
#

good idea

#

but timers are weird

#
timr += Time.deltaTime;
        if(timr >= 0.1f)
        {
            timr = 0;
           if (Input.GetButton("Fire1")){
                GameObject ball = Instantiate(projectile, transform.position,transform.rotation);
                ball.GetComponent<Rigidbody>().AddRelativeForce(new Vector3(0, 0,-launchVelocity));
           }
        }
        
      
    }
    
}
#

im gonna take a break too, do you wanna come back in 20?

hexed frost
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bleeddecay : MonoBehaviour
{
    public float bleedtimer = float.NegativeInfinity;
    // Start is called before the first frame update
    void Start()
    {
        bleedtimer = 0f;
    }

    // Update is called once per frame
    void Update()
    {
        bleedtimer += Time.deltaTime;
        if (bleedtimer >= 2) {
            Destroy(gameObject);

        }
    }
}
#

there's a simple one ๐Ÿ˜›

#

if that script is on a gameobject, the object will destroy itself 2 seconds after it is created

haughty basin
#

is bleed timer in seconds?

#

it dies out really early

hexed frost
#

yeah thats seconds - increase it if you want

#

lol was just thinking, this'll be the second time I've helped a student try and reach a late deadline last minute ๐Ÿ˜›

#

what are the assignment parameters?

haughty basin
#

alright im back

#

its not huge

#

just six thigns i have to do

#
X1. Game audio (sounds, music, etc.)
X2. Game Physics (RigidBody, Area2D, KinematicBody2D, Ray-casting, etc.)
X3. Game Math (vectors, Matrices, Curves, Paths, etc.)
4. Game Animation
5. Game Score
6. Player lives
X7. Collision detection
X8. User input (keyboard, mouse, microphone, touchscreen, etc.)
9. Saving a game
10. Loading a previous game
11. Pausing and resuming a running game
12. Networking
13. Multiplayer
14. Virtual Reality
#

the ones with x's are ones i have done

#

@hexed frost

haughty basin
hexed frost
#

so you need to do six of the 14?

haughty basin
#

yaeh

#

and ive done 5

#

so its not really last minute

#

i just have to give a presentation on this tomorrow

#

this entire game is based off of another game that was popular in the early 2000's

hexed frost
#

reminds me of 'a perfect tower'

haughty basin
#

i played this shit all the time when i was a kid

#

i plan to add just infantry units to kill (represented by the capsules

#

right now im trying to get the bleedtime to work right

#

its killing off the bullets way too early*

hexed frost
#

did you increase the time?

haughty basin
#

yeah

#

but it still seems to kill off at the same time

hexed frost
#

what did you increase it to?

haughty basin
#

30

#

they still die out in 2 seconds

#

or around 2.5 sceonds

#

its har dto sound

#

its hard to count*

#

3 seconds

hexed frost
#

lets see the script ๐Ÿ˜›

hexed frost
#

the version you are using

haughty basin
#

?

#

of unity?

hexed frost
#

you said you changed the timer

#

I wanna see it

haughty basin
#

the script is the same

#

but the timer is

#

30

hexed frost
#

you probably set it in the wrong place, let's see your script

haughty basin
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bleeddecay : MonoBehaviour
{
    public float bleedtimer = float.NegativeInfinity;
    // Start is called before the first frame update
    void Start()
    {
        bleedtimer = 0f;
    }

    // Update is called once per frame
    void Update()
    {
        bleedtimer += Time.deltaTime;
        if (bleedtimer >= 2) {
            Destroy(gameObject);

        }
    }
hexed frost
#

... nothing is changed there

haughty basin
#

exactly

#

i changed the bleeddecay timer

#

it was negative infinirt

#

infinity

#

but i changed to 30

hexed frost
#

in that script, change if (bleedtimer >= 2), into 30

haughty basin
#
if(30){
  Destroy(gameObject);
}
#

??

hexed frost
#

negativeinfinity is just a placeholder, that script sets it to zero at start

#

no, change the 2

#

into 30

#

the 2 is the two seconds...

haughty basin
#

oh ok

hexed frost
#

-_-

haughty basin
#

im sorry, i didn't know what it was there for

hexed frost
#

sorry I guess I could have been more clear

#

I am no professor

haughty basin
#

its ok

#

i just don't want ya to get too frustrated at me

hexed frost
#

well, I was right, you did set it in the wrong place lol

haughty basin
#

well it works now

#

now i gotta make the enemies die

hexed frost
#

so what you thinking for the last feature? I recommend against saving and loading, thats what I spent like ten hours today smashing my head against

haughty basin
#

well, i gotta make the enemies die, or else it isnt really a game

#

then.....

#

maybe pausing

#

pausing seems a lot easier

hexed frost
#

pausing pretty easy yeah ๐Ÿ™‚

haughty basin
#

and look

#

i added trees!

hexed frost
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;



public static class gamesaver
{
    public static string directory = Application.persistentDataPath + "/SaveData/";
    public static string filename = "SaveData.txt";

    public static void Save(SaveObject so)
    {
        string dir = Path.Combine(Application.persistentDataPath, directory);

        if (!Directory.Exists(Application.persistentDataPath))
        {
            Directory.CreateDirectory(Application.persistentDataPath);
        }

        string json = JsonUtility.ToJson(so);
        File.WriteAllText(dir + filename, json);
    
    Debug.Log(json);
    }

    public static SaveObject Load()
    {
        string fullPath = Path.Combine(Application.persistentDataPath, directory, filename);
        SaveObject so = new SaveObject();

        if (File.Exists(fullPath))
        {
            string json = File.ReadAllText(fullPath);
            so = JsonUtility.FromJson<SaveObject>(json);
        }
        else
        {
            Debug.Log("No save file");
        }
        return so;
    }

}```
#

there's 1/4 saving scripts I wrote earlier

#

pure... pain

haughty basin
#

its actually kinda looking good

hexed frost
#

and the damn thing doesn't even work properly, I'm back at er tomorrow to try and fix it

haughty basin
#

well i cant help, but i can be a mascot

#

lol

#

well, making the enemies die should just be as simple as..

#

should that go in the bullet script, or the enemy script?

hexed frost
#

on the enemies

#

then you can have OnTriggerEnter checking for the name/tag of the bullets

haughty basin
#

the collisions of the enemies should be trigger?

hexed frost
#

I find trigger collisions more reliable

haughty basin
#

alright they are triggers now

hexed frost
#

no wait

#

you are confusing Collisions with Colliders

#

change the enemy's collider back to non-trigger

haughty basin
#

done

hexed frost
#

the 'collision' refers to the interaction event between two colliders

#

only one of the two needs to be trigger for OnTriggerEnter

haughty basin
#

huh?

#

which one of the two

#

one of the two what

hexed frost
#

one of the two colliders making the collision needs to be trigger, in order to use OnTriggerEnter

#

since the bullet already is, the enemy doesn't need to be

haughty basin
#

right

#

so the kill command should be on the bullet

#

to check if its an enemy?

#

right?

hexed frost
#

nope, on the enemy, to check if its being hit by a bullet, unless you want the bullets to.. generate references to the enemies they hit, in order to destroy them ๐Ÿ˜›

haughty basin
#

oh ok

hexed frost
#

see what im sayin? the bullet won't know which enemy to destroy ๐Ÿ˜›

haughty basin
#

if(enemyhitbybullet){
 die();
}
hexed frost
#

more like:

#
void OnTriggerEnter(collider col)
{
if (col.tag == "bullet")
{
do the thing
}
}
#

I use tags for everything ๐Ÿ˜›

haughty basin
#

but you said to not make the enemy collider a trigger

hexed frost
#

I don't see how I have contradicted that

haughty basin
#

void OnTriggerEnter

hexed frost
#

yeah, one of the colliders needs to be trigger, doesn't matter which one

#

in this case its the bullet

haughty basin
#

oh ojk

#

something aint right

#

i feel like im close

#
void OnTriggerEnter(Collider col){
        if(col.tag == "bullet"){
            Destroy(gameObject);
        }
        
    }
hexed frost
#

in order to use .tag, you need to have the correct ... tag on the object

#

know how to set a tag?

haughty basin
#

no

#

can't it just be name?

hexed frost
#

no because they are named like.. clonesomethingsomething, right

haughty basin
#

yeah

hexed frost
#

because they are instantiated clones of a prefab

#

so in the inspector, in unity, in the top right, there's a dropdown for tags

#

down at the bottom, create a new one, called bullet

#

then, select the bullet prefab, and set its tag to that

haughty basin
#

done

hexed frost
#

test time ๐Ÿ™‚

haughty basin
#

BAM

#

cool

#

now i gotta add a death sound

#

thatll be easy

#

i can do that i think

hexed frost
#

probably a little trickier than you think - if you want the enemy to emit the death sound, you can't flat out destroy the gameobject, because the sound is on it ๐Ÿ˜›

haughty basin
#

nevermind

#

screw it

hexed frost
#

you'd have to.. disable it's meshrenderer first, play the sound, then destroy it

#

on timers ๐Ÿ˜›

haughty basin
#

ah screw it

#

it works

#

the game is functional now

hexed frost
#

ezpz ๐Ÿ˜„

haughty basin
#

now pausing

hexed frost
#

the key to pausing is:

#

Time.timeScale = 0;

haughty basin
#

yer kidding

hexed frost
#

and you turn it off by setting it back to 1

#

I was going to post my pausecontroller, but.. it has a whole bunch of other features

haughty basin
#

well this should just be easy as hel

#

if get button down pausebreak

#

then time scale 0

hexed frost
#
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (!deathtrackerref.deathactive)
            {
                if (menuactiondelay > 0.5f)
                {
                    if (!ispaused)
                    {
                        pausemenuanim.Play("pausefadein");
                        ispaused = true;
                        menuactiondelay = 0;
                        Time.timeScale = 0;
                        Cursor.lockState = CursorLockMode.None;
                        Cursor.visible = true;
                    }
                    else
                    {
                        pausemenuanim.Play("pausefadeout");
                        menuactiondelay = 0;
                        Time.timeScale = 1;
                        ispaused = false;
                        Cursor.lockState = CursorLockMode.Locked;
                        Cursor.visible = false;

                    }
                }
            }
        }```
#

I have a pause menu after pausing, so I run a bunch of animations, and need a delay so people can't just spam esc and get it caught mid menu-open or close

#

so you could basically take out evvvvverything except if input, if ispaused, and the two timescale and ispaused settings

#

and that'd be a wrap

haughty basin
#
     if (Input.GetKeyDown(KeyCode.Escape))
        {
          if (!ispaused)
            {
               Time.timeScale = 0;
               Cursor.lockState = CursorLockMode.None;
               Cursor.visible = true;
               ispaused = true;
            }
            else
            {
               Time.timeScale = 1;
               ispaused = false;
               Cursor.lockState = CursorLockMode.Locked;
               Cursor.visible = false;
            }
        }
hexed frost
#

now if you want to -do- anything involving time while timeScale is 0, you can use unscaledTime

#

that looks good

#

put it in an update method and try er out ๐Ÿ™‚

haughty basin
#

is cursor methods still a part of that?

hexed frost
#

if you want, they do what they say ๐Ÿ˜›

haughty basin
#

is paused does not exist

#

deleting

hexed frost
#

you'll need to declare it at the top

#

public bool ispaused;

haughty basin
#

damn it

#

i almost had that

#

i said boolean instead of bool

hexed frost
#

lol 'deleting'

haughty basin
#

no no

#

by declaring

hexed frost
#

oh you meant the cursor stuff

#

ye

haughty basin
#

btw it doesn't work

hexed frost
#

what doesn't work

haughty basin
#

escape to pause

#

no errors

hexed frost
#

lesse current script

haughty basin
#

leme try something

hexed frost
#

whole thing

haughty basin
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class pauseController : MonoBehaviour
{
    public bool ispaused;
    
    // Start is called before the first frame update
    void Start()
    {
        ispaused = false;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
          if (!ispaused)
            {
               Time.timeScale = 0;
               Cursor.lockState = CursorLockMode.None;
               Cursor.visible = true;
               ispaused = true;
            }
            else
            {
               Time.timeScale = 1;
               ispaused = false;
               Cursor.lockState = CursorLockMode.Locked;
               Cursor.visible = false;
            }
        }
    }
}

hexed frost
#

better to set it to false right at the top actually

#

public bool ispaused = false;

#

then you don't need that in start

haughty basin
#

escape doesnt work

#

oh im a dumbass

#

one second

#

where would i put the pausecontroller script?

hexed frost
#

on an object that will be active in the scene when you want to pause

#

I stick all my like, placeless scripts, onto my canvas

haughty basin
#

it works, but it doesnst stop the game

#

i put it on an empty game object

hexed frost
#

hmmm.. well all it is supposed to do it stop the game, so I don't know what you mean by it works

#

how does it work..

#

(but also not work?)

haughty basin
#

i can see the boolean going on and off

#

one sec

haughty basin
hexed frost
#

your camera movement works - does anything else?

#

do enemies move/bullets fire

haughty basin
#

yeah, the gun, the death

#

but the pause does not happen

hexed frost
#

so.. it's not pausing

#

hmmm

#

I.. have no idea.. it works for me

#

stops everything dead, I've used it identically for last three projects

haughty basin
#

holy hsit

#

now it works?

#

WTF?

#

ohhh

#

OHHH

#

IT DOES WORK

#

IT JUST THE TURRET STILL MOVES

hexed frost
#

ahhhh okay let's see your turret movement script

#

can probably tweak it so it wont

haughty basin
#
using UnityEngine;
using System.Collections;

public class CameraScript : MonoBehaviour {

    public float speedH = 2.5f;
    public float speedV = 2.5f;

    private float yaw = 0.0f;
    private float pitch = 0.0f;

    void Update () {
        yaw += speedH * Input.GetAxis("Mouse X");
        pitch -= speedV * Input.GetAxis("Mouse Y");

        transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
    }
}
hexed frost
#

try changing it to FixedUpdate

haughty basin
#

lmfao no

hexed frost
#

lol

#

worth a try ๐Ÿ˜›

haughty basin
#

im laughing hard

#

its not important

#

the turret cant fire

#

when paused

#

and also the enemies stop

hexed frost
#

well, you can get a reference to the pausecontroller in camerascript, and only do the movement if ispaused = true

#

er I mean false

haughty basin
#

nah

#

this is good

#

it is complete

#

but i gotta add WAY more enemies

#

so copy and paste time

hexed frost
#

why not make a spawner ๐Ÿ˜›

haughty basin
#

because i don't know how

#

lol

hexed frost
#

similar to how you make the bullet, just without adding velocity

haughty basin
hexed frost
#

too many navmeshagents will cause pathfinding problems ๐Ÿ˜›

haughty basin
#

thats why we gotta kill them

hexed frost
#

goal of game: prevent performance drops

#

๐Ÿ˜›

#

if you want 'flying' enemies, move the enemies collider and renderer way up above the navmeshagent ๐Ÿ˜›

haughty basin
#

:O

#

did u say flying enemies

hexed frost
#

they'll still technically be moving the same, with the navmeshagent on the ground, but it'll look like they are, however far above it you set them

haughty basin
#

oh well, id want them to be faster and stuff

#

btw, none of these enemies hurt the player

hexed frost
#

Hmm I can't tell if they are coming towards the player at all

haughty basin
#

they are

hexed frost
#

they look pretty stationary

#

ah okay

haughty basin
#

they just slow

hexed frost
#

did you want them to hurt the player?

haughty basin
#

i mean, whats a game if you cant lose?

hexed frost
#

welp, you'll basically do the exact same thing as the bullet killer, but with a script on the player, looking out for tag "enemy"

haughty basin
#

i dont think there even is a player value]

hexed frost
#

well, it'll need a collider

#

might as well make it trigger, so you can use the exact same technique

haughty basin
#

alright

hexed frost
#

also, Destroying the player won't really result in some kind of game end - I think you'll need to.. pause the game, display a message, and have a button to restart ๐Ÿ˜›

haughty basin
#

ill just send it back to the main menu

hexed frost
#

and if we're talking essential game elements, gonna need a score too ๐Ÿ˜›

haughty basin
#

if we are gonna go this deep, then i might as well add the flying enemies

#

and stuff

hexed frost
#

shrug I'm about off to bed

#

I'm usually working on my game from like 6am-6pm, then either bumming around discord or playing league in the evenings

haughty basin
#

ill just add the game over stuff

#

then ill wrap it up

#

youve been a big help.

#

ill refer back to this thread later to learn more

hexed frost
#

glad to help ๐Ÿ™‚

haughty basin
#

ill give you a copy of the game

#

can i dm you

hexed frost
#

.... meh ๐Ÿ˜›

haughty basin
#

..nevermind then .-.

hexed frost
#

you can, I don't really want it though ๐Ÿ˜›

haughty basin
#

ok

hexed frost
#

but yeah, you can for sure dm me, add as friend, join my discord

#

I'm pretty friendly ๐Ÿ˜›

chrome vale
#

I'm somewhat new to Unity and yesterday started messing around with NavMesh.

I want the enemy to follow the player if it can, which works. But when the player is unreachable and the enemy can't see the player through a raycast, I want to set the enemy's priority to instead of following, it'd try and get a view of the player for projectiles.

naive coral
chrome vale
#

Sorry, basically, letโ€™s say the player is on a platform the enemy canโ€™t get to. Instead of the enemy just walking underneath or to the wall of the platform and stopping, I want it to adjust its position to get a view of the player, like walking away from underneath the platform so it can see it, for example to allow the enemy to shoot projectiles at it while it canโ€™t reach the player

naive coral
chrome vale
#

I donโ€™t need it to jump, no not come closer, just walk into view of the player if the views obstructed really, I can give a better example once I get home if you need

naive coral
#

Actually wait that donโ€™t work

#

Let me think

chrome vale
#

Using a raycast is onto something Iโ€™m sure, I have one set up already going from player to enemy, just donโ€™t know how to handle the enemy walking back into view after itโ€™s view is obstructed, thatโ€™s the difficult part

naive coral
#

Why canโ€™t it just move toward the player until itโ€™s in its sights. Then stop the enemy?

chrome vale
#

because if the enemy were to be under this platform im standing on it wouldnt be able to do anything to shoot me, it'd have to back up from under it