#Share the entire script.

1 messages · Page 1 of 1 (latest)

glacial mural
#
public float moveSpeed;
public float originalMoveSpeed;
public Transform nextPoint;
public int travelDistance = 0;
public int whenToStart = 500;

[Header("Points")]
public Transform start;
public Transform point1;
public Transform point2;
public Transform point3;
public Transform point4;
public Transform point5;
public Transform point6;
public Transform end;

public void Update()
{
    if (whenToStart <= 0)
    {
        if (transform.parent.name == "onScreenEnemies")
        {
            transform.position = Vector3.Lerp(transform.position, nextPoint.position, moveSpeed * Time.deltaTime);
        }
    }
}

public void FixedUpdate()
{
    if (whenToStart >= 1)
    {
        whenToStart -= 1;

    }
    if (transform.parent.name == "onScreenEnemies")
    {
        if (whenToStart <= 0)
        {
            travelDistance += 1;
        }
    }
}
#
public void OnTriggerStay2D(Collider2D collision)
{
    if (collision.transform.tag == "Point")
    {
        if (Mathf.Abs(transform.position.x - nextPoint.position.x) <= 0.001f && Mathf.Abs(transform.position.y - nextPoint.position.y) <= 0.001f)
        {
            if (collision.transform.name == "point1")
            {
                nextPoint = point2;
            }
            else if (collision.transform.name == "point2")
            {
                nextPoint = point3;
            }
            else if (collision.transform.name == "point3")
            {
                nextPoint = point4;
            }
            else if (collision.transform.name == "point4")
            {
                nextPoint = point5;
            }
            else if (collision.transform.name == "point5")
            {
                nextPoint = point6;
            }
            else if (collision.transform.name == "point6")
            {
                nextPoint = end;
            }
            else if (collision.transform.name == "end")
            {
                if (transform.parent.name == "onScreenEnemies")
                {
                    gameVariables.GetComponent<waveSystem>().EnemyDefeated();
                }
                gameVariables.GetComponent<gameVariables>().currentGameHealth -= transform.GetChild(0).GetComponent<health>().currentHealthAmount;
                Destroy(gameObject);
            }
        }
    }
}

thats all the main stuff in the movement script

icy axle
#

please use one of the paste sites linked in !code for large amounts of code like this

dusk hamletBOT
icy axle
#

(and paste the entire script)

glacial mural
#

i dont have nitro so the message was too long

#

would it still work

icy axle
#

paste your code into the site and click the save icon, then copy the resulting link

glacial mural
#

You can watch this is slow mode to see that the closer those enemies are to that corner, the slower they were, until they hit that nextPoint, they all went back to normal speed

icy axle
#

you've uh

#

saved the page...?

#

just send the link

glacial mural
#

what, oh

#

(ive never used this)

icy axle
#

yes

glacial mural
#

ok

icy axle
#
    public void Update()
    {
        if (whenToStart <= 0)
        {
            if (transform.parent.name == "onScreenEnemies")
            {
                transform.position = Vector3.Lerp(transform.position, nextPoint.position, moveSpeed * Time.deltaTime);
            }
        }
    }
#

you're using Vector3.Lerp here

#

Vector3.MoveTowards isn't anywhere in this script

glacial mural
#

sorry, its supposed to be vector3.movetowards. i was trying new things

#

this is what i meant: transform.position = Vector3.MoveTowards(transform.position, nextPoint.position, moveSpeed * Time.deltaTime);

#

im failing so bad at sharing this code

icy axle
#

make sure you're still getting that behavior when using MoveTowards.

#

if you are, try commenting that out entirely and see if the enemies move at all

#

perhaps something else is interfering

glacial mural
#

the void update func?

icy axle
#

no, just that single line of code.

glacial mural
#

ok, one sec

#

enemies wont move at all

icy axle
#

okay, so the MoveTowards code should be fine in isolation

#

do the enemies have non-kinematic rigidbodies?

glacial mural
#

all enemies have this same 2D rigid body

#

i tried freezing both x and y, they still moved but the slowing down problem persisted

icy axle
#

It’s dynamic, so it will be affected by physics forces. Consider making it kinematic.

glacial mural
# icy axle It’s dynamic, so it will be affected by physics forces. Consider making it kinem...

OH MY GOSH. ITS BECAUSE THE Z VALUE GETS CHANGED EVERY TIME THE SAVED LOADED CLONE GETS PUT IN!!!! AFTER 3 HOURS, (thank you so much btw)

explanation: the normal Z value is supposed to be 1. when i saved a game and loaded it back in, the Z value of that clone went to a random high number like 147 or something. the reason we couldnt see the movement is because were looking at the game from the x and y perspective. vector3.movetowards is working perfectly and its moving at a constant speed, its just that the enemy was trying to get the same value of Z as its nextPoint!

that was brain killing man.. thank you so much for taking time to help me tho!

#

hopefully that made sense

icy axle
#

ah, that would do it

#

Turning off 2D mode can help you spot that kind of thing!

#

I didn’t think of that at all

glacial mural