#so how do i do it the right amount
1 messages · Page 1 of 1 (latest)
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
hold on
lemme try to comprehend this
those are a lot of words and im confused how we got there
you can put a speed variable instead of 0.5f
and can attach value runtime
to test it
yeah ik
but currently its instant
im honestly happy with any speed as long as it happens
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.
so theres no command to just smoothly do it in one command, i guess
Update works well usually
wait so whats the point of the speed variable if it does it in a single frame no matter the speed
read the documentation.
oh yeah i read that
but i didn't understand lol
no, actually read it, rather than just skimming it and then giving up
this is everything you need.
about what?
about what
current = top thing
current = current
i get it now
bruh
movetowards calculates the result of position1 + speed*target
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
then you assign it to your transform
would it not move it like a tenth of the way
but it goes to outpipe immediately
if inoffice and outpipe are 0.1 meters apart, this will take you straight to outpipe
they are not
if they aren't, then you're wrong. it doesn't snap it to outpipe instantly
they're like 2.75m
show your code.
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;
}
}
why do you need to run the code async
this will start a bunch of coroutines
or by coroutine
until y > 0.25f
uhh
every frame, if your position is low enough, it starts a new coroutine
they're all running at once
don't do that.
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
you already have this "scaring" variable
just use that
or add another one, perhaps
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
MoveTowards is literally designed to change something gradually over time
true, i think its meant for when the target is not right above the object