playMaker

Author Topic: crosshair help  (Read 1925 times)

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
crosshair help
« on: April 22, 2019, 05:18:54 PM »
i've a 3rd person charater who can aim and shoot in different directions.

with ability to switch between weapons (six of them).

I am using a sprite on each weapon choice, which i turn on / off when aiming.

All working fine, however the rotation of the sprite looks kinda odd.

Each weapon has its own spawn point for bullets, could I use this reference point to activate a line renderer maybe red to show target and bullet hit point.

my current issues lie with the sprite are the fact that it will go through walls and floors.

could I raycast get the hit point and use that hit point to tell the line renderer the distance?

Spawn a particle effect red glow at the end of the line renderer.

Sorry if i'm not making sense, but hopefully you get what i'm after.

Thank you for you time.

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: crosshair help
« Reply #1 on: April 23, 2019, 04:45:26 AM »
i've a 3rd person charater who can aim and shoot in different directions.

with ability to switch between weapons (six of them).

I am using a sprite on each weapon choice, which i turn on / off when aiming.

All working fine, however the rotation of the sprite looks kinda odd.

Each weapon has its own spawn point for bullets, could I use this reference point to activate a line renderer maybe red to show target and bullet hit point.

my current issues lie with the sprite are the fact that it will go through walls and floors.

could I raycast get the hit point and use that hit point to tell the line renderer the distance?

Spawn a particle effect red glow at the end of the line renderer.

Sorry if i'm not making sense, but hopefully you get what i'm after.

Thank you for you time.

Just to dabble to one part of your question;

In regards to things clipping through walls/being obscured, one way to get around this is to have 2 cameras. One camera is normal, but it's on the bottom (set as 2nd position), the other is set to only see a special layer you create just for the crosshairs, and is set to be on top. The cameras overlay together, so with the top position camera only seeing crosshairs and nothing else, nothing can get in the way of  seeing the crosshairs.

Just make sure both cameras have the same FOV or they won't line up.

This also means if you have some post processing or what ever on your main view, you don't have to have it on the crosshairs too.
« Last Edit: April 23, 2019, 04:47:56 AM by daniellogin »

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: crosshair help
« Reply #2 on: April 23, 2019, 02:17:27 PM »
thanks daniellogin, hmmm my crosshair is currently a part of the character and my current camera is similar to the stealth camera without all the bells and whistles.

To be honest, I am unsure how to set this up.

Besides this won't help with the current display of the crosshair.

I'd need a way for the crosshair to always face the direction of the player only whilst aiming.

I currently have an asset that does something as you say and its playmaker so ill take a look it could help, however, it's a first-person style.




daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: crosshair help
« Reply #3 on: April 24, 2019, 03:05:42 AM »
thanks daniellogin, hmmm my crosshair is currently a part of the character and my current camera is similar to the stealth camera without all the bells and whistles.
It doesn't matter if the crosshair is a Child of the character or any other part, as long as it's a Gameobject. If it's a Gameobject, you simply go to the Inspector in unity and use the Layer drop down to choose a layer. You will need to make a new one, but simply use that Layer drop down to select new, it will take you to a list of all layer, then click the + or what ever button it is there to add one. Name it something like crosshair so you can know what it's for later.
Then go back to the crosshair Gameobject, the layer drop down again, this time your new layer is there, so click it.

I don't know about the stealth camera, but I don't think that's relevant, because this is fundamental unity stuff so not really going to be interfered with by any bells or whistles.
Quote
Besides this won't help with the current display of the crosshair.
Yeah I know. That's what made my first reply just a 'dabble' :)
Quote
I currently have an asset that does something as you say and its playmaker
We are in the Playmaker forum right now :)

As far as your actual problem with sprite alignment goes; I don't normally do much with sprites/2d, other than putting it on a Canvas on the camera.

If it's like a normal 3d gameobject, maybe you need to use 'Look At' (with Playmaker) which runs every frame and targets your camera.
https://hutonggames.fogbugz.com/default.asp?W100

It will rotate the object so it looks at the camera. However, are your shots coming from? This would be most suitable if you are raycasting from the center of the camera or something, but may be misaligned if you are aiming from elsewhere.

« Last Edit: April 24, 2019, 04:14:13 AM by daniellogin »

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: crosshair help
« Reply #4 on: April 24, 2019, 04:27:30 AM »
Oh right, forgot to mention a step.

So I said how to set a layer to a gameobject, but what you have to do after that is set the cameras up.

Make two cameras. You already have one. Make sure both cameras have the same FOV and are positioned in exactly the same place. Maybe parent one to the other, or have both in the same parent and set to 0, 0, 0 transform for each so they are in hte same place.

For your second camera, go to it's settings and click on the Culling Mask. It's a drop down that will show you all of the layers. They start out checked, so un tick all of the except your new layer. This tells it only see that layer and nothing else.
This shows how: https://docs.unity3d.com/Manual/Layers.html

Next you want it to not show the skybox. You change the Clear Flags setting to Depth Only (I think. It's one of the settings anyway).

Now go to the Depth setting. It starts at 0. Keep your main camera on 0 set your new camera (crosshair only) to 1. This puts the new camera on top of your main one.
See here: https://support.unity3d.com/hc/en-us/articles/214371766-How-do-I-force-my-cameras-to-render-in-a-certain-order-

So basically, your camera on the top layer can only see the crosshair so can never be blocked from seeing it. This camera will render over your main game camera, but can't be blocked by anything the main camera sees.

Maybe you will want to change the culling on your main camera though to set it to not see the new layer. This will avoid drawing it twice and will help if you have any post processing or etc not rendered on to the crosshair.
« Last Edit: April 24, 2019, 04:30:10 AM by daniellogin »

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: crosshair help (SOLVED)
« Reply #5 on: April 24, 2019, 06:03:46 PM »
Thank you so much for the very detailed reply. Clipping solved