Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by AusAndrew19 · Aug 16, 2012 at 11:15 PM · positionfps

Weapon Possition Move On Sprint

Hi Guys!!! Haven't been on Answers for a while since my computer pooped itself lmao... I'm trying to figure out to create a script for run position... like... if i press the shift key and i start sprinting i want my weapon to drop.. like these pics.

Normal: http://imageshack.us/photo/my-images/809/normala.png/

How i want it to be when i sprint: http://imageshack.us/photo/my-images/41/sprintr.png/

any info will be appreciated on this matter. thank you :)

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DESTRUKTORR · Aug 17, 2012 at 03:00 AM

There's a number of ways to do this, as with many simpler mechanics/systems people usually ask for help with on here (not that there's anything wrong with that just... be prepared for a slew of options :P).

  1. Use an animation. Simple as that. Make the animation, and make it play when you sprint.

  2. Manually rotate the gun, over time. Quaternion.slerp is pretty good for this. You may also need Vector3.Lerp.

  3. Rotating/transforming with Time.deltaTime (the amount of time between the last frame update and this one) multiplied by some number is another way to manage doing something "over time," so I would suggest using it alongside a rotation/translation call.

Off the top of my head, those three would be the most practical. If you've got any specific questions on them, check the documentation links, or drop a comment, and I'll try to answer them.

Comment
Add comment · Show 4 · Share
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 AusAndrew19 · Aug 17, 2012 at 12:43 PM 0
Share

Okay... i looked at Quaternion.slerp and this seems good... but the basic function is

var from : Transform; var to : Transform; var speed = 0.1; function Update () { transform.rotation = Quaternion.Slerp (from.rotation, to.rotation, Time.time * speed); }

How would i create a if statement for it only to happen if i press the "Sprint" Button...

avatar image DESTRUKTORR · Aug 17, 2012 at 06:26 PM 0
Share
 var gunTrasnform : Transform;
 var sprintRotation : Quaternion;
 var normRotation;
 var rotationRate : float;
 var isSprintRotated = false;

 function Start()

 { 
     normRotation = transform.localRotation;
 }

 function Update()
 {
    if(Input.GetButton("sprint")) 
    { 
        gunTrasnform.localRotation = Quaternion.Slerp(gunTrasnform.localRotation, sprintRotation,Time.deltaTime*rotationRate);     
        if(gunTransform.localRotation==sprintRotation)     
        {
            isSprintRotated=true;
        }   
    }
    else if(!Input.GetButton("sprint")&&isSprintRotated)    
    {        
        Quaternion.Slerp(gunTrasnform.localRotation, normRotation, Time.deltaTime*rotationRate);
    }
  }

I think this should work... forgive me if there's some syntax errors... I'm a C# programmer, but I know enough Java Script to translate, for the most part.

Also, be sure you enter the "sprint" key in the Input menu, in the editor. You can find it under Edit>Project Settings>Input

avatar image AusAndrew19 · Aug 19, 2012 at 12:12 AM 0
Share

There was few errors but i fixed those... Thanks for this :)

avatar image DESTRUKTORR · Aug 19, 2012 at 02:41 PM 0
Share

No prob :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Camera Recoil,Please help me. 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to make an enemy change tags after death. 3 Answers

Why does this script only play like 0.3% of my animation 1 Answer

How to make a image flash infront of the camera 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