#Carrying objects in first person. Help please!

1 messages ยท Page 1 of 1 (latest)

storm beacon
#

I sent this in the "Code-General" server earlier today. it has since gotten a little buried so I made a thread for it. Any help on this is greatly appreciated!

#

even if you can just get me in contact with this creator. Youtube is blocking me from progressing at this point.

storm beacon
#

Just came to mind: its probably worth including this clip here for added context:) This is the current behavior I am experiencing.

#

Carrying objects in first person. Help please!

young rampart
#

heres a script i made.. i don't really have alot of time to look or debug your code.. but since i seen this yesterday I figure'd i'd share my code and how i did mine..
Its a single script (you can add it to to any gameobject)
it just needs a reference to the Camera that ur using (we use the camera to raycast)

for the setup the things u interact w/ need a collider and a rigidbody.. (with the main root/rigidbody tagged as Pickeable or w/e layer you chose to use)

#

i also thought.. since u said u couldn't even get the others to work in the first place this could be a good starting point.. (atleast i know it works).. as i just sent the video of it working..

storm beacon
#

Thank you so much! I will give this a go!

young rampart
#

just check it out.. read thru it.. try to figure out how it works.. and all that jazz

#

learning by reverse engineering basically

storm beacon
#

In either case I will be reverse engineering it for the new input system. I just want to see if something works at all, or if something else in my set up might be causing conflicts or something

young rampart
#

trying to anticipate any error or trouble u might encounter

#

and a screenshot of the object's inspector so u can peep the setup

#

but yea.. anyway see how we're the only ones in here..
you'll have to recruit people to help you out and send em this way using the link...
most people aren't gonna stumble in here unless they're asked..
and u can always just ask ur question again.. just attach the link along w/ it..
each time u may get a nibble here and there ๐Ÿ‘

storm beacon
young rampart
#

ya, u just gottta find a good time-window..

storm beacon
#

Now I understand you don't advise directly implementing this code "mindlessly" however I did, again, just to zero in on what the cause might be, and this was my result:

young rampart
#

plus.. people are more likely to help when people come w/ specific questions..
like: im following this tutorial.. and he uses rigidbody.AddForce().. and what i dont understand is .. this this and this...

storm beacon
storm beacon
young rampart
#

^ people might jump in and answer

if ur like: hey, im following this tutorial.. and i can't figure it out..
^ people might ignore something like that.. as it means we'd have to dive into ur setup, ur system.. and all that

young rampart
#

but most times its like.. "dang, bro i got my own bugs i can't even figure out.."

young rampart
# storm beacon

not exactly sure whats happening in that video..
i'd try to debug as much of the script as u can..

#

maybe somethings getting called more than u think it is..

#

like its picking and dropping the object many many times a second for example

storm beacon
#

im not even getting any of those debugs you included

young rampart
#

thats y in the code i sent u i added those debugs..
its nice to see

-> click started
-> object detected
-> object picked up
-> click ended
-> object dropped

#

did u add the script to a gameobject??

#

wont run unless u do..

storm beacon
#

does this work?

young rampart
young rampart
#

i'd say
first:

  • make the script work (a debug log in the start should help)
    next:
  • make sure the input in the script works (when you click the mouse button it should log a message)
    then:
  • make sure the object has the correct layer assigned to it.. and that layer is also assigned in the Lift3D script..
  • debug inside the raycast to make sure we're hitting that object and doing all that jazz
    finally:
  • debug any actions or logic you do after picking up the object
#

just do it step by step.. working ur way to a completed system..
as soon as something doesn't work as expected u can stop.. and work out that.. and then continue on..

just saying.. piece it up to make it easier to learn/understand/build..

#

too many times ppl will do the full thing.. and at the end it doesn't work.. but they never debugged along the way.. soo theres no telling what part about it that doesnt work.. this makes the whole debugging process much more frustrating..

storm beacon
#

how am I supposed to debug when it only tells me "LayerMask"

young rampart
#

you can add debugs however u want..

#

i gave u the script as an example... not as a finished product..

#

here's the newer script.. w/ the debugs i added

storm beacon
#

okay I see now, I was overlooking the debugs that were including in the original. Thank you

young rampart
young rampart
#

the layermask debug was for someone earlier.. that was trying to figure out layermasks.. i just forgot to remove it

storm beacon
#

Ha! I appreciate this a ton so far. thank you so much. Ill see what i can figure out!

young rampart
#

good luck ๐Ÿ€ i gotta get to work on my own bugs now lol

#

and just so u know.. this isn't a finished script by no means..
i was still gonna go back in and make sure that it rotates w/ the player.. (that way if u spin in a circle the cube doesn't rotate the other direction)
and i was gonna add in some limits.. so it doesn't rotate a full circle..
and i might even go in and add some rotation keys that i can press to make it rotate while im holding it..

#

just figured i'd share it since it isn't finished.. and its nothing really special just yet

#

and its using Layermask to detect what can and can't be picked up..
soo u can change it or use w/e layer u want.. just don't forget to go and mark the objects to be using that Layer (whichever one u chose)

storm beacon
#

if Im understanding this correctly. It appears that its calling the release function before I actually release the mouse button. that's probably what causes it to freak out. But I don't see any issue there. and it worked fine for you๐Ÿค” or am I looking at this wrong?

young rampart
#

it could be that it just logged it out of order

#

u can just test that specifically if u want..

#
 void Update()
 {
     if(Input.GetMouseButtonDown(0))
     {
         Debug.Log("Press");
     }

     if(Input.GetMouseButtonUp(0))
     {
         Debug.Log("Release");
     }

     /*
     
     // Raycast to get the point in front of the camera
     Ray ray = mainCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
     Vector3 followPosition = ray.GetPoint(presetDistance);

     if (Input.GetMouseButtonDown(0))
     {
         TryPickup(ray);
         Debug.Log("We pressed the Left Mouse Button");
     }

     if (Input.GetMouseButtonUp(0))
     {
         Release();
         Debug.Log("We released the Left Mouse Button");
     }

     if (isPickingUp)
     {
         // Update targetPosition to be at the preset distance from the camera
         targetPosition = followPosition;
     }

     */
 }```
#

/* code in between */ is just a big block comment.. so just like

// this```
#

soo.. here ^ i just commented out the rest of the logic and simple is debugging the press and release

storm beacon
#

I watch the console as I test. Press and release trigger on time every time according to my mouse. Physics just dont seem to behave with the object

young rampart
#

soo.. if that works as it should.. we can mark that as being a -non issue.. and move along.. uncomment the block.. remove the extra inputs

young rampart
#

we eliminate one thing as the issue.. and now we can focus on that.

#

process of elimination.. ๐Ÿ’ช

#

i notice i do use Extrapolate as the interpolation setting..

#

that kinda helps smooth out harsh rotations and movements..

#

but other than that.. i'd just say make sure that theres no other scripts or code that may be influencing the rigidbody as the pickup script is doing that.

#

and i think the way i wrote the script means the mass of the object doesn't matter.. (the forces will act the same no matter what the mass is).. but w/o looking i can't be ๐Ÿ’ฏ sure on that.. soo may be beneficial for u to test w/ different masses, different damping settings etc

#

i use 50 apparently

storm beacon
#

No other scripts on the objects, Extrapolate didn't make a difference, I also just tried setting mass to a basic cube to 50 too, no difference. However: I do notice that the debug for "It isn't close enough." Never fires. Just says that it is when i pick it up.

young rampart
#

interesting...

#

yea, that conditional should fire/log if you click looking at something thats in the raycast layer..
but is > than the PickupDistance variable

#

nvm im wrong..

#

i dont get that log either.. b/c since we define the distance of our raycast as being pickup range it never actually goes into that code-block.. unless we're close enough anyway

#

so, b/c we use that as the rays distance.. it'll never not not be close enough

storm beacon
#

I see, check that off as a non issue lol

young rampart
#

if we changed this to 100 we'd probably get that log.. b/c theres times when the raycast would hit the object and when the if(distanceToHit <= pickupRange) part runs.. it could potentially be false

storm beacon
#

interesting! lol

young rampart
#

i guess u could use that as something else.. like a UI Prompt that pops up
when close enough to see the UI but not close enough to pick up the object

#

maxDetectionDistance and then pickupDistance or something

#

this is all Raycast stuff..

#

once u figure out and learn how they work and what function parameters/overloads they take they get easier

storm beacon
#

gotcha. I can see use for that. So if all my debugs check out, that doesn't eliminate the code from being problematic right? I mean, I'm lead to believe its something else in my set up, due to it working on your end. Here's something I maybe should have clarified earlier; my navigation and look script runs with the new input system. does any of this rely on old system mouse inputs? I understand that it uses the old system, but would there be a conflict in using the new system for navigation in this case?

young rampart
#

w/ minimal setup.. so im guessing ya its ur setup some how..

#

in some fashion

storm beacon
#

poking around some more with those lift force, damping, etc.. values seems to be helping, it might just require some fine tuning of those values.

#

there is still inconsistency though interestingly. It behaves worse and worse each time I pick it up

young rampart
#

lol..

#

ya, it takes time to find good values..

#

i tend to stick close to 0.. and just ever so gradually working them all out

#

or 1 rather sometimes

#

it depends on if its a multipler.. code *= thatValue or its additive or something else

#

cuz anything * 1 = itself

#

soo usually its a good starting ground when adding in those types of things

storm beacon
#

why would the bahavior change each time i interact with it? even if I go from one object to the next. same progressively weirder behavior.

young rampart
#

that doesn't sound like anything i would have the answer to.

#

it should def not.. the code runs the exact same each time u play-test

storm beacon
#

yea when i restart it I can pick it up just fine again. but only the first time. this is so strange!

#

I'm really surprised how hard it is to make things interactable for me. I'm sure this is a walk in the park for you lol. Should I dial back to something easier? does such thing exist? This seems like one of the easier parts of a 3D game that I'm struggling to figure out. Most of this process was just missing small things that made all the difference but now I'm just drowning out here lol. It really doesn't help that I'm trying to learn the new system. most guides are very old and don't use it lol. All I want is to make my game accesible with rebindable keys. and as far as I can tell this is the only way.

storm beacon
storm beacon
#

should I try to switch it back to the old input system for nav and look? even if that's not what I want/need. would that be worth doing to potentially get the same exact result?

#

or could I try installing your package? maybe my mouse is screwed up? according to the debugger its fine. but idk atp. I have tried a different mouse already though.

#

or should I just start over completely and see if it tweaks out again? Perhaps I corrupted something important? I genuinely have no clue. Idk how you even began to learn all this lol!

ornate nest
#

@storm beacon hi

storm beacon
#

hi sorry!

ornate nest
#

make sure you're using the links

storm beacon
ornate nest
storm beacon
#

yea both mine and from spawncamp

ornate nest
#

weird. Cause it seems its trying to move in 2 different spots at same time or something

storm beacon
#

yea its quite interesting lol

ornate nest
#

Wish I knew why all those calculations cause mine was a bit simpler..

storm beacon
#

first one I tried was pretty simple too, worked on a differnet premace by parenting to an empty inside of your camera. but that had similar results

ornate nest
#

why is this one commented out btw
//pickedObject.AddForceAtPosition(force, pickedObject.position + pickupOffset, ForceMode.Acceleration);

ornate nest
storm beacon
#

not sure, I think this script they used to help other people with other stuff on, so that might be from something else

ornate nest
#

that was there in the video too ?

storm beacon
#

They didnt show their script in any of the videos, just it playing at runtime. but said it was the same one that they pasted in for me

ornate nest
#

ohh so it wasnt even explained what script does? just a copy pasted script?

storm beacon
#

there were efforts to explain it, and I was advised to attempt to reverse engineer it. I just wanted to implement it to make sure something else on my set up isnt causing issues. since many guides have left me fruitless, im suspicious its cause is due to something else in my project

ornate nest
#

maybe, hard to say what that is. Unless its something wrong on the rigidbody itself

storm beacon
#

If it worked, I was going to have to figure it out to implement the new input system on it, but it didnt so im lead to believe I have other issues somewhere. would it be worth making a new file, and just making navigation and look run off the old system? I dont see how the 2 differnent systems could conflict this, but maybe a new file would also help. but at that point im changing more than one variable and i wont know what fixed it.

young rampart
#

was gnna re-attempt it later

ornate nest
#

holy hell lol

young rampart
#

all the extra calculations are just spring stuff..
oh btw.. this script needs rigidibodies to be the outter most objects.. (no parents)
if theres parents to the rigidbody it automatically complicates things b/c of relative positioning.. and scaling..

the other way i see this done is by parenting gameobjects to another gameobject attached to the player.. (i didn't wanna go that route).. soo if ur needing something like that you'll have to keep ur search up..
you've gotten all the raycasting and stuff working..

#

only difference is my rigidbodies are calm and collected..

#

urs are eratic and circus-esque

#

its only (1) script.. can be attached to anything b/c it reference the main camera..

#

and then theres 1 layer that i used in my layermask.. theres really nothing that could be going that wrong w/ it

storm beacon
young rampart
#

implementing the new input system to it would be simple..

#

thats why i used Press() and Release()

#

u'd just call the exact same methods w/ the new input system stuff

storm beacon
#

call "TryPickUp" and "Release"? does that still interact with the other methods in the script?

young rampart
#

my script also has the half-life bug too

storm beacon
young rampart
#

TryPickUp()

#

w/ the ray above it or u could build the ray Inside TryPickup() either way

young rampart
#

like i said.. its not a finished system by any means ๐Ÿ˜„

storm beacon
#

oh!๐Ÿ˜† funny enough I would be perfectly okay with that bug in this game

#

in fact i encorage it lol

ornate nest
#

good ol prop surfing

young rampart
#

thats it ^

#

couldnt think of hte word

ornate nest
#

shit.. I miss gmod

storm beacon
#

https://paste.mod.gg/iroybfosghmd/1 okay.. kinda a different issue here. still related. I'm just trying to trigger this with the new input system to avoid conflicts. but now there's no interaction at all. it'll still fire the debug for "Lets try to pick up the object" but it seems to stop there๐Ÿค”

#

I would send a clip but it would be like watching paint dry๐Ÿ˜†