- Home /
How would you implement ADS for Custom Scopes?
Just a basic question here:
I have a game that has guns that can be found in the world, each gun can have a different scope. Example: A player can find a pistol, and put a RDS scope on it through the attachments menu.
Each gun has an empty gameobject called "ScopePivot" and this is where the scope is placed when the player selects it in the attatchments menu. When the scope is placed in attachments menu, its parent is set to the "ScopePivot" object, and its local transform is reset as well. This way any scope can be easily attached to any gun.
I was trying to find a way to implement Aim Down Sights. I have settled on lerping the scope to right in front of the cameras position, however because the scope is child on the gun, only the scope will move if I use this technique. This will leave a floating scope in front of the camera, and a gun still by your side in the idle animation.
Any suggestions on a good way to implement Aim Down Sights with my setup. Keep in mind that each scope will be a different height, width, ect...
I don't need the code written for me as I'm fairly experienced in C#, but if anyone has a basic idea of how they would, or have, implemented this, it would be much appreciated.
Please comment if you think me explanation is hard to understand, as I can reword it or add pictures.
THANKS
How about a second camera and align that to the scope centre?
Answer by Eno-Khaon · Jul 29, 2015 at 12:55 AM
When you attach the scope to the gun, you're effectively defining a local position relative to the gun.
It looks like what you need to do is figure out where the scope will need to be positioned relative to the player, then move the gun with the offset of the scope's position to where the scope would go.
So, if you have the scope working correctly, you should have most everything done already. You'd already know where the scope is at relative to the gun and where the scope needs to be relative to the character/camera. Therefore, in order to put the gun into the correct position, you'd want to determine where the scope needs to move to, but move the gun instead to that position minus the offset of the scope from the gun.
// Hardly a good example, but just showing what I'm getting at.
public Vector3 scopeToCameraOffset; // Position of scope relative to camera
Vector3 scopeDestination = Camera.main.transform.position + scopeToCameraOffset;
Vector3 scopeToGunOffset = scope.transform.position - gun.transform.position;
Vector3 gunDestination = scopeDestination - scopeToGunOffset;
Your answer
Follow this Question
Related Questions
Aiming down gun scope 1 Answer
How to bring reticles in different situations to the center of the camera? 0 Answers
Changing camera position to shoot through scope on gun 1 Answer
Gun Scope Not Centered 1 Answer
How To Make A Gun Scope Zoom In 2 Answers