• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Aug 22, 2013 at 02:05 AM by Benproductions1 for the following reason:

Question is off-topic or not relevant

avatar image
1
Question by moinchdog · Oct 29, 2012 at 09:38 PM · aimdownscopesights

free aim down sights script here

This is an AimDownSights script. Its like the one on UnifyCommunityWiki, but I rewrote it and improved it This is free but give credit where its due.

Dj

 var gun : Transform; //Drag you Gun transform into This
  var curField = 60.0;
  private var dampVelocity2 = 0.4;
  var nextVector : Vector3; //Sights Transform
  var curVector : Vector3; //Normal Transform
  
  var curY = 234.8665; //Normal Rotation of Gun
  var nextY = 230.7; //Rotation of Gun when looking down Sights
 
  
  class weaponStats {
      var curDamage : int; //Normal Weapon Damage
      var nextDamage : int; //Sights Weapon Damage
      var gunScript : String;
      var mainCam : CrossHair; //Change "CrossHair" to the name of the Script or GUITexture you use for your CrossHair
  }
  var speed : float = 0.1;
  var stats : weaponStats;
  
  function Update () {
      //Smooth Changine Vield of View of Camera
     var newField = Mathf.SmoothDamp(Camera.main.fieldOfView, curField, dampVelocity2, .3);
     Camera.main.fieldOfView = newField;
  
     if (Input.GetButton("Fire2")) { //"Fire2" is right click, can be changed
         //adjust viewpoint and gun position
         curField = 40;
         //Rotating Gun to look down Camera Perfectly
         transform.localRotation.eulerAngles = Vector3(0,nextY,0);
  
         //slow down turning and movement speed
         transform.root.GetComponent(CharacterMotor).movement.maxForwardSpeed = 2.5;
         //Adjust Gun Damage
         GetComponent(stats.gunScript).damage = stats.nextDamage;
         stats.mainCam.enabled = false;
         //Moving the gun
         transform.localPosition = Vector3.Lerp(transform.localPosition,nextVector, 0.3);
     } else {
         //adjust viewpoint and gun position
         curField = 60.0;
         transform.localRotation.eulerAngles = Vector3(0,curY,0);
         //speed up turning and movement speed
         transform.root.GetComponent(CharacterMotor).movement.maxForwardSpeed = 10;
         stats.mainCam.enabled = true;
         GetComponent(stats.gunScript).damage = stats.curDamage;
         transform.localPosition = Vector3.Lerp(transform.localPosition,curVector, speed);
     }
  }
Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sparkzbarca · Oct 29, 2012 at 09:47 PM 0
Share

this isn't a question. Post in unity wiki and update the wiki with it if its better. :) Thanks for posting a free script!!!

avatar image chris.dalayap · Jan 19, 2013 at 12:44 PM 0
Share

What type of script is that?.. C#? Javascript?

avatar image Vraduer · Jan 25, 2013 at 10:07 AM 0
Share

The type of this script is JavaScript for the people who are asking

avatar image HSMInteractive · Aug 22, 2013 at 12:38 AM 0
Share

What do I attach this to?

avatar image getyour411 · Aug 22, 2013 at 12:50 AM 0
Share

For an improved version, you might consider optimizing this and reducing the transform and GetComponent calls from Update

http://unitygems.com/script-interaction1/

avatar image OP_toss · Aug 22, 2013 at 01:20 AM 0
Share

While this is great to see someone post free code, I have a few reservations with it...

  • It's not a Question, as @sparkzbarca pointed out, so put it elsewhere. Wiki or Forum perhaps?

  • It's in Javascript. I feel like C# is the only way to go for serious Unity devs.

  • It's not optimized, as @getyour411 pointed out.

  • It doesn't make sense that looking down the sight of a gun changes its damage. It should only affect its accuracy/spray, which is not implemented in this solution.

  • It's variable names aren't all that descriptive, although I appreciate the comments!

  • It comes with no instructions on how to use it, what it depends on, etc...

So thanks for writing this, but I'm sorry I don't feel it's up to snuff to be promoted and learned from by people striving to learn Unity.

Just my opinion, don't mean to sound harsh. Thanks for the effort!

avatar image Benproductions1 · Aug 22, 2013 at 02:06 AM 0
Share

The question is now closed. If you want to post free code I suggest either the forums or the Wiki, NOT Unity Answers

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

aim down sights of gun 3 Answers

Aimdown Sights Toggle 1 Answer

How do you aim down sights 1 Answer

I can't aim up and down in my FPS game I've tried to use scripts of the internet but its not working. 1 Answer

Aim down sights ( javascript ) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges