Raycasting Help

I want to shoot a ray from my gun. This is not an FPS this is a 2D game. Everyone online declares a ray as if it were an FPS. How can I declare a ray that shoots from the tip of my gun? I also want to have an inaccuracy effect so it needs to scatter a little bit. How can I go about doing this? Thanks and sorry for the noob question

As it’s a weapon effect, you could use a simple mesh that looks like a laser/ray and stretch it from PointA (your gun) to PointB (enemy). You could also use some other ways for this like drawing a line, or using the lineRenderer.

The Ray, most people say is simply an invisible line that get’s drawn from somewhere, mostly the Camera position to check if it hit’s something. If it hits something and it’s an enemy, they instantiate a bullet or whatever that goes from the origin towards the enemy… So it’s mostly used to check if you can hit something… the visual part is still made kinda different.

No I want to raycast instead of instantiated bullets. How do I use a raycast from my gun? I know what a ray cast is. I dont want a laser

BUMP

Are you trying to use Raycast as a graphic effect? If you are then stop… raycast is a physics method not a graphic generator.

If you are going for the graphic effect you would instantiate a gameobject same as you would a bullet and just manipulate the object however you see fit to accomplish the look you desire.

If you are looking for the actual Raycast for the physics returns its as simple as

the origin would be your gun tip so its yourgun.transform.position + change it so that it is coming from the end of your gun rather than the center

The direction you can get with simple trig and maincamera.

Not quite what you require but this might help you http://gluedbrain.blogspot.in/2013/06/unity3d-car-game-tutorial-10-adding.html

You must use a texture and the texture position…
You will have some problems since you can’t rotate textures… (as far as I know…)