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 AdvsNoob · May 27, 2013 at 09:30 PM · animationfpsweapon systemweaponchangingfps-controller

Animating a weapon into/out of player view

What I want to do is basically animate the weapon from the bottom and slide it up like he pulled it out of his sling or something. But I have never really done animation before. All I have is the actual weapon model and I attached it to the FPS player main camera. Can someone help guide me in the correct direction :] Please and thank you!

Comment
Add comment · Show 1
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 clunk47 · Aug 09, 2013 at 05:21 PM 1
Share

Please either accept an appropriate answer, let us know if this issue has or has not been resolved, or close your quesion.

1 Reply

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

Answer by clunk47 · May 27, 2013 at 09:38 PM

You could make the animation in your 3D program(Blender, Maya, etc...), and code it to Play the animations whenever... OR you could use a simple script in JS or C# using Vector3.MoveTowards like so. This is a simple C# EXAMPLE.

 using UnityEngine;
 using System.Collections;
 
 public class EXAMPLE : MonoBehaviour
 {
     Vector3 showPos;
     Vector3 hidePos;
     bool hide = false;
 
     void Start()
     {
         showPos = transform.position;
         hidePos = showPos + Vector3.down;
     }
 
     void Update()
     {
         if(hide)
         {
             transform.position = Vector3.MoveTowards(transform.position, hidePos, 1.0f);
         }
 
         else if(!hide)
         {
             transform.position = Vector3.MoveTowards(transform.position, showPos, 1.0f);
         }
 
     }
 }

This is just an example to get you pointed in the right direction.

Comment
Add comment · Show 7 · 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 clunk47 · May 27, 2013 at 10:22 PM 1
Share
 GetComponent<EXA$$anonymous$$PLE>().hide = true;
 

GetComponent Reference.

avatar image AdvsNoob · May 27, 2013 at 11:05 PM 1
Share

Thank you :] Now its just the matter of making the hand/item follow the player and move it up and down ^_^

avatar image clunk47 · May 27, 2013 at 11:13 PM 1
Share

Just make the player the parent of your "hand object". $$anonymous$$ake the hand object the parent of your weapon. Then you'd want to attach your movement script the the hand object, not the weapon. Since the weapon is a child of the hand object, it will move where then hand object moves. Since the hand object is child of your player, it will do the same in respect to the player. Parent Ref

avatar image clunk47 · May 27, 2013 at 11:18 PM 1
Share

If you want to do a "bob" up and down when walking, you could use the same principle as above. But since it's continuous you would want to check when the object meets a certain position, so it can move back the other direction. Here's an example of that:

 Vector3 startPos;
 Vector3 stopPos;
 Vector3 targetPos;
 bool isWalking = true;
 
 void Start()
 {
     startPos = transform.position;
     stopPos = startPos + Vector3.down;
     targetPos = stopPos;
 }
 
 void Update()
 {
     if(isWalking)
     {
         transform.position = Vector3.$$anonymous$$oveTowards(transform.position, targetPos, 1.0f);
     } 
 
     if(transform.position == stopPos)
     {
         targetPos = startPos;
     } 
 
     if(transform.position == startPos)
     {
         targetPos = stopPos;
     }
 }
avatar image clunk47 · Jul 24, 2013 at 11:07 PM 1
Share

I don't see how you could be getting a nullref ex in this specific code. Everything is defined. Post the FULL error. It will tell us what script and what lines of the script are throwing the error.

Show more comments

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

14 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

Related Questions

Animating different Weapons 2 Answers

How to reset gameObject position when switched back to? 0 Answers

Best weapon system for multiplayer FPS? 0 Answers

Vector3.Lerp and Animations 0 Answers

How to create a stationary weapon FPS controller ? 2 Answers


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