#Carrying objects in first person. Help please!
1 messages ยท Page 1 of 1 (latest)
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.
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!
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..
Thank you so much! I will give this a go!
just check it out.. read thru it.. try to figure out how it works.. and all that jazz
learning by reverse engineering basically
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
https://www.nombin.dev/9syhldl0exu92avqfyd32afj
here, I added in a few debug logs to kinda step thru the process
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 ๐
thank you! I've linked it a couple times but it quickly gets burried by other discussions even after I bump it. I have no problem waiting I was just concerned I was doing something wrong lol!
ya, u just gottta find a good time-window..
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:
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...
makes sense, I did say a lot for just wanting someone to look over it lol
^ 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
ya, u might get lucky if something interests someone about that..
but most times its like.. "dang, bro i got my own bugs i can't even figure out.."
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
im not even getting any of those debugs you included
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..
does this work?
it should.. yes..
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..
how am I supposed to debug when it only tells me "LayerMask"
you can add debugs however u want..
i gave u the script as an example... not as a finished product..
A website to host temporary code snippets.
here's the newer script.. w/ the debugs i added
okay I see now, I was overlooking the debugs that were including in the original. Thank you
ya the first one i sent was my version.. i just removed the layermask debug and just added some generic ones in each chunk
the layermask debug was for someone earlier.. that was trying to figure out layermasks.. i just forgot to remove it
Ha! I appreciate this a ton so far. thank you so much. Ill see what i can figure out!
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)
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?
its got the same time stamp..
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
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
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
good good.. soo thats debugging in a nutshell..
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
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.
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
I see, check that off as a non issue lol
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
yup, had to confirm that im not telling stories lol
interesting! lol
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
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?
same code works in my project..
w/ minimal setup.. so im guessing ya its ur setup some how..
in some fashion
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
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
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.
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
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.
definitely not my first time experiencing such inconsistencies either, like my original thread post said. following that tutorial gave me 2 wildly different results. and ever since the first partial success. the objects have been twitching like crazy whenever I interact with them.
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!
@storm beacon hi
https://www.nombin.dev/ibr2mge18wf0rgjo7wnranzz yup! pretty much the same as they sent me earlier
A website to host temporary code snippets.
oh alr. and this is the same script a video is using ?
yea both mine and from spawncamp
weird. Cause it seems its trying to move in 2 different spots at same time or something
yea its quite interesting lol
Wish I knew why all those calculations cause mine was a bit simpler..
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
why is this one commented out btw
//pickedObject.AddForceAtPosition(force, pickedObject.position + pickupOffset, ForceMode.Acceleration);
nah I also use Rigidbody and holdPos-current
not sure, I think this script they used to help other people with other stuff on, so that might be from something else
that was there in the video too ?
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
ohh so it wasnt even explained what script does? just a copy pasted script?
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
maybe, hard to say what that is. Unless its something wrong on the rigidbody itself
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.
i tried that method and couldnt get it to work so i commented out the AddForceAtPosition and the position offset code
was gnna re-attempt it later
#1353059934920642582 messagegoes way back to original video w/ the script and its logs..
#1353059934920642582 message
and the setup
holy hell lol
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
#1353059934920642582 message not to be doing anything like this atleast
I was suspicious of parenting/children causing issues. which is why i made that basic cube again
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
call "TryPickUp" and "Release"? does that still interact with the other methods in the script?
my script also has the half-life bug too
should i know what that means lol?
TryPickUp()
w/ the ray above it or u could build the ray Inside TryPickup() either way
yea it means this can happen
like i said.. its not a finished system by any means ๐
oh!๐ funny enough I would be perfectly okay with that bug in this game
in fact i encorage it lol
good ol prop surfing
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๐ค
A tool for sharing your source code with the world!
I would send a clip but it would be like watching paint dry๐