#Hitscan gun
1 messages · Page 1 of 1 (latest)
apologies for being a bothered just needed quick help is all with the hitscan situation since im awfully new to c#
No problem
If you want to use a hitscan I suggest looking into Raycasting
You can creating a ray and then fire it straight out in the direction youâre looking
i see
From there you can take the object you hit, and deal damage if itâs an enemy, or place a bullet decal at the position, etc.
i see
Yep
any tutorials out there you recommend
Itâs fairly simple to setup
If I were at my computer Iâd give an example
Just create a new ray, and use Physics.Raycast to cast out
You can create a RaycastHit object to store the result of that, and pass it in using the âoutâ keyword
gosh you are going to hate me i have no idea how to do that also should i create a completely new script for it
Nope, you can create a new object by creating a local variable
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(transform.position, someDirection, out hit)
{
Debug.Log(âIâve hit: â + hit.transform);
}
From there you can access whatever you need on the hit object
so just copy this into my fps controller script
Well, you need to swap out someDirection for the direction youâd like to shoot
If your controller is working correctly Iâd probably suggest using the cameraâs forward transform so it always fires where youâre looking
ahh jeez hm...question will you be available tomorrow possibly to help me over a vc
i am sadly a much better auditory learner
im looking at this and i feel like it should be simple im just way too confused
Ah no problem
I suggest taking a look here https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
Unfortunately I wonât be able to help in VC, but I wish you luck
If you still canât figure it out tomorrow I can possible give you a code example
But you donât have to rely on me, learning to use Google effectively is an extremely important skill thatâll get you much further than help forums will
okie dokie thx so much for the help