#moving object to vector3 point

1 messages · Page 1 of 1 (latest)

agile peak
#

ok so when paused, an object sways around, and when unpaused the object stays in the last position of the sway. this is not supposed to happen because of the vector point

#

@night solar @stone delta

stone delta
#

You want your object to return to vector's position when W is pressed up?

#

but it doesnt?

agile peak
#

moving object to vector3 point

#

yes

night solar
#

@stone delta vector is a position that's stored when entering the pause mode, and the idea is to go back to that position when unpausing

stone delta
#

it is because you use getkey, which keeps updating vector's position

agile peak
stone delta
#

that's why you should use getkeydown

night solar
#

Does the object have an animator component?

#

Or anything else that changes its position

stone delta
#
        {
            cam.Sway();
        }``` put this before the input ifs
agile peak
stone delta
#

then use if else

agile peak
#

but its set to root motion so it shouldnt affect transform

#

okay

stone delta
#

i mean, if else on the input ifs

night solar
#

I bet its because of the animator changing your position

stone delta
night solar
#

What if you just disable the animator?

agile peak
#

let me disable animator and see

#

nope same thing

#

doesnt move back to the vector point

stone delta
#

what does your code look like now?

night solar
#

What if you change Update to LateUpdate?

night solar
stone delta
agile peak
#

wait forgot the else if

stone delta
agile peak
#

late update didnt work either

night solar
night solar
#

And when its false it should stay at vector?

agile peak
#

move back to vector yes

night solar
#

Add this

       if(!inPaused)
        {
           transform.position = vector;
        }```
#

So it overrides it every frame

agile peak
#

should I still keep late update?

#

or regular update

night solar
#

LateUpdate Im pretty sure because it gets called after animations

agile peak
night solar
#

Have you logged the inPaused yet and made sure it works like you want

#

True when holding, false when released

agile peak
#

okay

stone delta
#

also debug vector

agile peak
#

i think i figured the problem out

#

when debugging inPaused, its true both times

#

I think its this line

#
            {
              inPaused = true;
              vector = transform.position
            } ```
#

Because I'm always setting it to true

#

Even when its false

#

Im gonna try something

stone delta
agile peak
#

what do you mean?

#

if its not paused the vector should be the transform.position

stone delta
#

is there other way you can pause the game?

agile peak
#

no?

#

its just W

agile peak
stone delta
agile peak
#

this is the updated script

night solar
#

I told you to debug the values like an hour ago but hey lets waste everyones time instead

stone delta
#

does isPaused even debug false at first?

agile peak
night solar
agile peak
#

wait

#

nvm

#

i did something wrong

stone delta
#

force initialize the static false

night solar
#

I bet hes changing it somewhere else

stone delta
#

and can you make it private, so that we can be sure nothing else is modifying it?

agile peak
#

yes it debugs false

#

in start

stone delta
#

then in update becomes true even you're not pressing anything?

agile peak
#

even when its private its still true both times

agile peak
#

only true when pressing W

#

and false in start

night solar
#

But does it go to false when you let go of W

agile peak
#

no

#

still true

night solar
#

How did you make it private? Other scripts are using that bool, right?

agile peak
#

let me share current code

agile peak
#

i just removed those

#

and just made the bool private

stone delta
agile peak
#

let me try that

night solar
stone delta
#

you sure you getting 0 errors?

agile peak
#

but now im gonna debug vector

stone delta
#

should be true followed by a false magic debug

agile peak
#

yea

#

thaat works

#

i might be doing vector debug wrong as well

#

but im debuggin vector under vector = transform.position;

#

then

#

Debug.Log($"transform:{transform.position}");

#

in the getkeyup

#

they r both the same

#

idk whats wrong

#

probably my debugging

stone delta
agile peak
#

okay

#

they r the same thing

stone delta
#

that's is supposed to happen

#

do you sway the camera?

agile peak
#

no just the object

stone delta
agile peak
#

should I move the sway to late update?

agile peak
#

its a seperate game object

stone delta
#

isnt sway in the late update already?

stone delta
agile peak
agile peak
#

im calling it from that script

stone delta
#

where did you attach this Pause script?

agile peak
#

Game manager

#

object

stone delta
#

you are moving that gamemanager?

agile peak
#

nope

#

another object

stone delta
#

omg @night solar

agile peak
#

what should I change?

#

?

#

was that the problem?

#

wait should I move my sway logic to this pause script or something?

stone delta
#

this Pause script should be attached to the player you are moving

agile peak
stone delta
#

ye...

agile peak
#

oh

#

let me move it then

#

it works

#

thanks

#

i cant believe that was the problem

#

sorry

stone delta
#

the transform key calls the transform of where you attach the script

#

it's just a shortcut of GetComponent<Transform>

agile peak
#

okay

#

thanks

#

sorry for wasting your time

night solar
#

Well, good that its fixed... hope you learned some troubleshooting at least, george