#Hitscan gun

1 messages · Page 1 of 1 (latest)

empty nest
#

Alright can you share the code?

#

Either use a screenshot or format

#

@whole gate

whole gate
#

apologies for being a bothered just needed quick help is all with the hitscan situation since im awfully new to c#

empty nest
#

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

whole gate
#

i see

empty nest
#

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.

whole gate
#

i see

empty nest
#

Yep

whole gate
#

any tutorials out there you recommend

empty nest
#

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

whole gate
#

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

empty nest
#

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

whole gate
#

so just copy this into my fps controller script

empty nest
#

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

whole gate
#

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

empty nest
#

Ah no problem

#

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

whole gate
#

okie dokie thx so much for the help