- Home /
Deadfrontier type crosshair
Been at it all day cant get the player object to follow the cross hair. The player does turn but the problem is the mouse can and does go everywhere on the screen as if there is no point for a cross hair at all. Im making a topdown shooter/3rd person game. I see in other examples that people tend to set a laser sight on their game to replace cross hairs is that because nobody can figure out how to effectively make the player turn exactly in a 360 radius without mouse becoming unaligned?
I'm pretty stuck here all help is greatly appreciated...
The script im using is one from the fps tut.
The crosshair script
var position : Rect; var
crosshairTexture : Texture2D;
function OnGUI () {
position = Rect( Input.mousePosition.x - (crosshairTexture.width / 2),
(Screen.height -Input.mousePosition.y) - (crosshairTexture.height / 2),
crosshairTexture.width, crosshairTexture.height );
GUI.DrawTexture( position , crosshairTexture );
}
I have a regular camera set up and I've tried placing the standardize mouse look script on the player and that failed. I have tried using the mouse orbit script but it didn't seem to much different from mouse look as the crosshair would still become unlined as I walked through the level turning.
PS the title is just there to further explain what I'm trying to accomplish as a means of crosshair ability
Answer by Lilius · Jan 24, 2015 at 07:29 PM
Create new game object under your gun game object. Position game object at desired distance forward from gun barrel and add visuals for your crosshair. This way crosshair is always where the gun is pointing at. No scripts needed if your gun is always pointing forward.
If you're using reload animation or some other animations where gun might be pointing to sky or ground, disable crosshair game object for animation duration to prevent it from flying around player.
Your answer
Follow this Question
Related Questions
Camera Setup for Top Down Shooters 3 Answers
How do I create a shmup in Unity? 2 Answers
Topdown Shooter 1 Answer
2D Platform Shooter Camera Controls C# 0 Answers