Hello Guys,
I have yet another question, yes, I have lot’s and lot’s of questions :p.
I have been busy trying to create a FPS project, but, I am not much of an FPS player, I think the last FPS I played was Unreal Tournament way back when. So I’m not particularly good at explaining what I want nor have an example.
So, what I am trying to do at the moment is get the gun to be following the mouse cursor exactly - that I will eventually replace with a “dot” or cross-hair when I get around to it - at the moment the mouse cursor moves around and the gun sort of follows it around with a gap that gradually increases as the mouse gets further away on the x axis - and on the y-axis the gun it stops at a certain point both up and down. I really don’t mind that it stops (probably some sort of gimbal thing) it just that the cursor keeps going throwing out the alignment further especially when I have the game windows minimized within Unity.
I am really after hints and/or tips rather than having one of you do it for me - so I can learn for myself. Like what sort of things I need to look at that will help me accomplish this goal, for example, do i need to look at the FPS controller, character motor or modifying the mouse look script? I really am in the dark on this.
Thankyou and Regards,
CK.
We’d be better able to help seeing some code. And I’d say this is likely a scripting question.
I have been using bog standard code when it comes to controlling the gun. I just made the gun a child of the camera so it controls the movement somewhat. The shooting controls are all pretty standard fare as well press the “fire1” button and it shots a prefab with the OnCollisionEnter handling the firing of the projectile, explosion, and destroying of the projectile. Haven’t actually gotten much further than that with regards, to things that can be hit. Although I have some things that are able to be hit they are just your stock standard rigidbody objects.
In the future I intend to use Raycasting to know when enemies are in the zone and can be shot by having the cross-hair or other change colour - but I haven’t got that far yet!
So there is no real need to see any scripting as yet on the gun control because there ‘really’ isn’t any other than what is shipped with Unity! Which is why I’m looking for ideas as to how it might be done more precisely. I’m sure it can be done - well, I hope it can!?!
What most people do if they don’t use Unity’s build in fps controller (which I think is great and haven’t found a need yet to heavily modify it) is lock the cursor to the screen center and calculate the movement delta from center, convert to world space and apply that to the gun’s motion. Make sure to multiply by deltatime as well. It both makes movement consistent over framerate dips, and makes the overall feel very smooth.
I can’t give any more advice without seeing what you’re currently doing.
Aha - now that is a great tip! That really gives me something to work with.
Thanks heaps .