#Tap
1 messages · Page 1 of 1 (latest)
Idk how to do it concretely but in theory, get the touch coordinates and convert that to world space
I think the most confusing part about this is, that a friend who helped with the script originally decided to use physics.raycast for another script that kinda does what I need
for (var i = 0; i < Input.touchCount; ++i) {
if (Input.GetTouch(i).phase == TouchPhase.Began) {
// Construct a ray from the current touch coordinates
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
// Create a particle if hit
if (Physics.Raycast(ray))
Instantiate(particle, transform.position, transform.rotation);
}
}
This might be of help
Read the original thread:
https://answers.unity.com/questions/1075737/casting-a-ray-at-touch-position.html
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
if (raycastManager.Raycast(new Vector2(Screen.width / 2, Screen.height / 2), s_Hits,
The important thing is that when user taps on the screen, you want to run that raycast through the camera's view point. You must make sure you direct that ray as per the view frustrum of the camera, otherwise you'd just shoot it directly forward as if you're in orthographic mode.
In perspective camera mode (I'm assuming this is what you're using), your camera will angle out the further to the edge you are, so you must make sure to account for it
Understood
I think I messed up by letting a friend help me for this project
Kinda being thrown into a script that already has a bunch of connections/references that makes it so I can't just replace parts without destroying entire sections
And I'm not at a level where I understand what is being referenced too/what its function is completely
I'll look into everything you said though, appreciate the help
Using existing code is tougher, true. But it can teach you a lot more why we code the way we do
I think its also having different names for the same thing per script
I wouldn't worry too much if I were you, just start a new project and toss and turn with whatever piece of logic you want to test out, when you're done bring in that code into your project
Yeah if you started out with poor code it's going to be a bigger headache lol. If you're not comfortable with coding yet it's best to start with a blank project and test things out that way
Definitely true, kinda time sensitive though which makes it a pain
Then you can attempt some refactoring with your friend's project. Ask them to guide you if you get lost.
Yeah, at work we do the isolated project to get it figured out quick. If it works in isolation but doesn't in integration then we've got some ghosts in the code that we need to exorcise 😆
Good luck, I'll toss some lines in mine and then bounce for the day.
Hahahaha
Good luck to you too, thanks for the help.
Definitely gonna do a deep dive into unity programming after this project and just be able to take my time/explore
Love the idea that you can create pretty much anything once you know how to/understand the tools given
Enjoy your day!
Absolutely, same to you. And I'm a beginner at Unity too