#so how do i do it the right amount

1 messages · Page 1 of 1 (latest)

gentle geyser
#
Vector3 result = Vector3.MoveTowards(Vector3.zero, Vector3.right, 0.5f);
#

the result vector will move towards [1,0,0] by a distance of 0.5f

narrow silo
#

hold on

#

lemme try to comprehend this

#

those are a lot of words and im confused how we got there

tame narwhal
#

you can put a speed variable instead of 0.5f

#

and can attach value runtime

#

to test it

narrow silo
#

yeah ik

#

but currently its instant

#

im honestly happy with any speed as long as it happens

gentle geyser
#

smooth movement requires for you to move the object many times

#

you're just moving it once

#

move it many times. you can write a coroutine that uses Vector3.MoveTowards in a loop.

narrow silo
tame narwhal
#

Update works well usually

narrow silo
#

wait so whats the point of the speed variable if it does it in a single frame no matter the speed

gentle geyser
#

read the documentation.

narrow silo
#

oh yeah i read that

narrow silo
#

but i didn't understand lol

gentle geyser
#

no, actually read it, rather than just skimming it and then giving up

#

this is everything you need.

narrow silo
#

yeah i read that

#

but i was confused

#

WAIT

gentle geyser
#

about what?

tame narwhal
#

about what

narrow silo
#

current = top thing

gentle geyser
#

current = current

narrow silo
#

i get it now

gentle geyser
#

the current parameter

#

yes

tame narwhal
#

bruh

gentle geyser
#

that's why it's in monospace

#

it's referring to the parameter named current

narrow silo
#

i thought it meant like, electricity or something

#

because im slow

tame narwhal
#

movetowards calculates the result of position1 + speed*target

narrow silo
#

if so then, why does this:

weegeeinoffice.transform.position = Vector3.MoveTowards(inoffice, outpipe, 0.1f);

snap it to the position and not just move it a little bit

tame narwhal
#

then you assign it to your transform

narrow silo
#

would it not move it like a tenth of the way

gentle geyser
#

no, it moves 0.1 meters

#

it moves from inoffice to outpipe by up to 0.1

narrow silo
#

but it goes to outpipe immediately

gentle geyser
#

if inoffice and outpipe are 0.1 meters apart, this will take you straight to outpipe

narrow silo
#

they are not

gentle geyser
#

if they aren't, then you're wrong. it doesn't snap it to outpipe instantly

narrow silo
#

they're like 2.75m

gentle geyser
#

show your code.

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

public class weegeescript : MonoBehaviour
{
    public bool scaring;

    public Vector3 inoffice;
    public Vector3 outpipe;
    public Vector3 atpipe;

    public GameObject weegeeinoffice;

    void Start()
    {
        StartCoroutine(startcor());
    }
    void Update()
    {
        if (!scaring)
        {
            transform.position += new Vector3(0,-1f * Time.deltaTime,0);
        }
        if (transform.position.y <= 0.25f)
        {
            scaring = true;
            StartCoroutine(popOut());
        }
    }
    IEnumerator popOut()
    {
        weegeeinoffice.transform.position = Vector3.MoveTowards(inoffice, outpipe, 0.1f);
        yield return new WaitForSeconds(UnityEngine.Random.Range(3,5));
        weegeeinoffice.transform.position = Vector3.MoveTowards(outpipe, inoffice, 0.1f);
        transform.position = atpipe;
        scaring = false;
    }

    IEnumerator startcor()
    {
        yield return new WaitForSeconds(3);
        scaring = false;
    }
}

tame narwhal
#

why do you need to run the code async

gentle geyser
#

this will start a bunch of coroutines

tame narwhal
#

or by coroutine

gentle geyser
#

until y > 0.25f

narrow silo
#

uhh

gentle geyser
#

every frame, if your position is low enough, it starts a new coroutine

#

they're all running at once

#

don't do that.

narrow silo
#

uh oh

#

well that makes sense then

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

public class weegeescript : MonoBehaviour
{
    public bool scaring;

    public Vector3 inoffice;
    public Vector3 outpipe;
    public Vector3 atpipe;
    public Vector3 offit;

    public GameObject weegeeinoffice;

    void Start()
    {
        StartCoroutine(startcor());
    }
    void Update()
    {
        if (!scaring)
        {
            transform.position += new Vector3(0,-1f * Time.deltaTime,0);
        }
        if (transform.position.y <= 0.25f)
        {
            scaring = true;
            transform.position = (atpipe + offit);
            StartCoroutine(popOut());
        }
    }
    IEnumerator popOut()
    {
        weegeeinoffice.transform.position = Vector3.MoveTowards(inoffice, outpipe, 0.1f);
        yield return new WaitForSeconds(UnityEngine.Random.Range(3,5));
        weegeeinoffice.transform.position = Vector3.MoveTowards(outpipe, inoffice, 0.1f);
        transform.position = atpipe;
        scaring = false;
    }

    IEnumerator startcor()
    {
        yield return new WaitForSeconds(3);
        scaring = false;
    }
}

here we go, i made it so the y changes to be 0.05 greater when it gets to that y level

#

well it still doesn't work tho

#

it still snaps to be in position

gentle geyser
#

you already have this "scaring" variable

#

just use that

#

or add another one, perhaps

narrow silo
#

oh yeah

#

right

#
    void Update()
    {
        if (!scaring)
        {
            transform.position += new Vector3(0,-1f * Time.deltaTime,0);
        }
        if (transform.position.y <= 0.25f && !scaring)
        {
            scaring = true;
            StartCoroutine(popOut());
        }
    }

right, well i used the scaring variable

#

it still snaps to the position

#

you know, for all this effort i should probably just do position =

#

yeah its definitely better to not use movetowards because thats meant for other stuff

gentle geyser
#

MoveTowards is literally designed to change something gradually over time

narrow silo
gentle geyser
#

it's meant for moving from one value to another value

#

is the object not starting at inoffice?

#

if so, it'll snap to that position

narrow silo
#

my bad, im back now

#

it starts inoffice