Hi. I am quite new in unity scripting and I have a lot’s of ideas for games in my mind. I like concept of a game called raft and I want to make a survival game similar to that one but I can’t find any tutorial how to script to pick up items only when you are looking at them and you are close enough (most of them are just shows scripts where you go to the item and you pick it automatically). I watched some tutorials about inventory but most of that stuff is quite confusing for me. I would appreciate any help.
I don’t even know how anyone could possibly respond usefully to this.
I recommend you go back to the tutorial that seemed the easiest or closest to your problem (there are literally hundreds of inventory tutorials on Youtube!) and when you reach a point that you don’t understand, use the Unity documentation to look up keywords in the code, go back over what the tutorial dude said, etc.
When all that fails, come on back here, post the small snippet of code that you’re having trouble with (remember code formatting! See first post in the forum) and your specific question, what you tried, etc., and we’d be happy to help.
I will check video again and thank you so much for responding.
Some key things that might help - look into raycasting. Raycasting from screen (= your eyes) to world can be done using Camera’s ScreenPointToRay method.
Then you can use Vector3’s Distance method to get distance to object.
Here’s one good tutorial on topic (IIRC):
Yeah I mean that to me is the un-fun part of programming, taking human-level concepts like “looking at” and “close enough” and turning it into code-level calls like Physics.Raycast() as eses linked. Some of the magic feels lost when you break things down into actual code.
It’s a little bit analogous to magic tricks in real life.
Remember the first time you saw a really good magician make something disappear?
Then you saw the Youtube showing how he did it?
To me that isn’t “magic lost” so much as it is “magic understood.”
Going back I remember the first time I saw PONG and saw the paddle hitting or missing the ball.
To me that was magic.
Almost immediately I got into game programming and as soon as I made my own two virtual objects hit and miss each other, it was like a whole new world opened. I had understood that magic.
he should also probably look into these topic:
1.vectors
2.normal vectors
3.dotproduct (of normal vector)
Thank you so much for this replay I totaly forgot about raycast.