#I want to drop when hold is false

1 messages · Page 1 of 1 (latest)

knotty wasp
dull steppe
#

can you give more context

knotty wasp
#

I can pick up an drop objects with e

#

But I also want drop it when magicka is < 1

#

So when magicka < 1 hold variable turns false

#

In line 60 it checks if hold is true

#

Even if the hold is false it continues carrying the object

dull steppe
#

bc on fixedupdate it only checks for currentobject, not for hold

knotty wasp
#

I think I tried it but got an error

#

theres no error but nothing changed

dull steppe
#

send me the if condition

knotty wasp
#
void FixedUpdate()
    {
        if (hold == true)
        {
            if (CurrentObject)```
dull steppe
#

pro tip: instead of nesting conditions just do if(hold == true && CurrentObject)

#

pro tip2: dont need to check if its true, just check the variable if(hold)

#
  1. if it still drags the object then hold is true
#

add a print check everytime you set it true

#

be sure to add the line in the print check so its easier to know where its setting true

#

then check where its supposed to turn false

#

check the conditions

dull steppe
knotty wasp
#

I mean after you said

#

tried this one too

dull steppe
knotty wasp
#

what do you mean by print check like this?
Debug.log(hold)

dull steppe
#

i mean print("hold line: n")

knotty wasp
dull steppe
knotty wasp
dull steppe
knotty wasp
#

print(hold , line: 80);

dull steppe
#

its a string bud

#

use ""

#

print("hold, line:80");

knotty wasp
#

It just writes hold, line:80 in console what am I going to do with that?

dull steppe
#

now add one here to check if its changing

#

but dont use " this time

#

just print(hold)

knotty wasp
#

under the iff statement or update

dull steppe
#

under if statement

#

btw is your problem hold not updating when magicka going 0 or it still dragging while hold is false

knotty wasp
#

just doesnt drop it

dull steppe
#

oh alr then

#

still, add the print(hold) under the if statement

#

actually add it in update

#

ok so this is the line that drags your object right

dull steppe
#
void FixedUpdate()
    {
        if (hold && CurrentObject)
        {
            Vector3 DirectionToPoint = PickupTarget.position - CurrentObject.position;
            float DistanceToPoint = DirectionToPoint.magnitude;

            CurrentObject.velocity = DirectionToPoint * 12f * DistanceToPoint;
        }
    }```
#

ok so if you are dragging the object it means that hold is true

#

meaning hold isnt false as you expected

#

add a print for magicka on update too

#

try also just pressing E to release the object and see if that works

knotty wasp
dull steppe
#

can you tell me how much is decrease?

knotty wasp
#

I can change it its 50 now

#

it was 20 before

#

when it hits like 1 hold turns false and magicka starts increasing

#

but doesnt drop

dull steppe
#

alr, so every frame that magicka is greater than 1 and its holding it decreases

knotty wasp
#

yeah

dull steppe
knotty wasp
#

variable turns false I can see it

dull steppe
#

on the line that checks if magicka is below 1 it doesnt set hold as false

dull steppe
knotty wasp
#

on console

dull steppe
knotty wasp
#

Debug.Log(hold);

dull steppe
#

add a print("holding") below the if statement on fixedupdate

#

check if its beeing printed

#

when hold is false

#

also be sure youre saving your script

knotty wasp
#

it always true when true and false when false on console

dull steppe
#

i know

#

i said check if "holding" is beeing printed when hold is false

dull steppe
knotty wasp
#

you mean a new variable or

dull steppe
#

what

dull steppe
#

then return to me

knotty wasp
#

Oh okay now I understood why we are doing this

dull steppe
#

alr

knotty wasp
#

it only wrote once

dull steppe
knotty wasp
knotty wasp
dull steppe
#

yea, i mean your character kept holding the object in game

knotty wasp
dull steppe
#

uhh cant help you blud

#

i tried everything

knotty wasp
#

oh wait

#

I can drop it but I cant pick anything up later

#

and I need to press e one more time to set gravity to normal

dull steppe
knotty wasp
dull steppe
#

create a new function

#

in that function write this

#

CurrentObject.useGravity = true;
CurrentObject = null;

#

you're gonna call that function here and here

knotty wasp
#
    {
        CurrentObject.useGravity = true;
        CurrentObject = null;
    }```
dull steppe
#

tell me when youre done and if it worked

knotty wasp
#

Bro thanks you so much

#

it worked

#

but when I kill a enemy that I'm holding

#

it says NullReferenceException: Object reference not set to an instance of an object

#

because it is null I think

dull steppe
#

thats a fire idea

dull steppe
dull steppe
#

but your fixedupdate still tries to use it

knotty wasp
#

yeah

dull steppe
#

do a check if its null on the end of update

#

if it is, hold=false

#

just do if(!CurrentObject)

#

of if(CurrentObject == null) if you prefer

knotty wasp
#

Brooooo thanks you so much man

#

it worked finally 😆

dull steppe
#

np

knotty wasp
#

and also thanks for spending an hour for me

#

😀