• 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 alexkarak · Sep 27, 2019 at 04:10 PM · cameracamera-movementshootingthird-personaim

Third person camera aim

hey guys i have a third person character and i want to make him pick up objects and throw them! But the camera is rotating fast and the object is thrown in a "random" point and not where i want! so i want to aim first and then throw it in the camera direction! This is my script but whatever i am trying in the aim void doesnt seem to work! (I want to access my main camera via this script if possible and not have multiple scripts) Pleas help me ...i am stuck in this part for a week!

 using UnityEngine;
 using System.Collections;
 
 namespace RootMotion.Dynamics
 {
 
     /// <summary>
     /// A point in the character's bone hierarchy for connecting props to.
     /// </summary>
     [HelpURL("http://root-motion.com/puppetmasterdox/html/page6.html")]
     [AddComponentMenu("Scripts/RootMotion.Dynamics/PuppetMaster/Prop Root")]
     public class PropRoot : MonoBehaviour
     {
 
         // Open the User Manual URL
         [ContextMenu("User Manual")]
         void OpenUserManual()
         {
             Application.OpenURL("http://root-motion.com/puppetmasterdox/html/page6.html");
         }
 
         // Open the Script Reference URL
         [ContextMenu("Scrpt Reference")]
         void OpenScriptReference()
         {
             Application.OpenURL("http://root-motion.com/puppetmasterdox/html/class_root_motion_1_1_dynamics_1_1_prop_root.html");
         }
 
         [Tooltip("Reference to the PuppetMaster component.")]
         /// <summary>
         /// Reference to the PuppetMaster component.
         /// </summary>
         public PuppetMaster puppetMaster;
 
         [Tooltip("If a prop is connected, what will it's joint be connected to?")]
         /// <summary>
         /// If a prop is connected, what will it's joint be connected to?
         /// </summary>
         public Rigidbody connectTo;
 
         [Tooltip("Is there a Prop connected to this PropRoot? Simply assign this value to connect, replace or drop props.")]
         /// <summary>
         /// Is there a Prop connected to this PropRoot? Simply assign this value to connect, replace or drop props.
         /// </summary>
         public Prop currentProp;
         public Rigidbody rb;
         public float thrust;
         /// <summary>
         /// Dropping/Picking up normally works in the fixed update cycle where joints can be properly connected. Use this to drop a prop immediatelly.
         /// </summary>
         public void DropImmediate()
         {
             if (lastProp == null) return;
             puppetMaster.RemoveMuscleRecursive(lastProp.muscle, true, false, MuscleRemoveMode.Sever);
             lastProp.Drop();
 
             currentProp = null;
             lastProp = null;
         }
 
         private Prop lastProp;
         private bool fixedUpdateCalled;
 
         void Awake()
         {
             // If currentProp has been assigned, it will be picked up AS IS, presuming it is already linked with the joints and held in the right position.
             // To pick up the prop from ground, assign it after Awake, for example in Start.
             if (currentProp != null) currentProp.StartPickedUp(this);
         }
 
         void Update()
         {
             if (!fixedUpdateCalled) return;
 
             // If dropped by another script or PuppetMaster behaviour
             if (currentProp != null && lastProp == currentProp && currentProp.muscle.connectedBody == null)
             {
                 currentProp.Drop();
                 currentProp = null;
                 lastProp = null;
             }
         }
 
         void FixedUpdate()
         {
 
             fixedUpdateCalled = true;
             if (currentProp != null && Input.GetMouseButton(1))
             
                 Aim();
 
             if (currentProp == lastProp) return;
 
             // Dropping current prop
             if (currentProp == null)
             {
                 puppetMaster.RemoveMuscleRecursive(lastProp.muscle, true, false, MuscleRemoveMode.Sever);
                 lastProp.Drop();
             }
 
             // Picking up to an empty slot
             if (lastProp == null)
             {
                 AttachProp(currentProp);
             }
 
             // Switching props
             if (lastProp != null && currentProp != null)
             {
                 puppetMaster.RemoveMuscleRecursive(lastProp.muscle, true, false, MuscleRemoveMode.Sever);
                 AttachProp(currentProp);
             }
 
             lastProp = currentProp;
             
         }
 
         private void AttachProp(Prop prop)
         {
             prop.transform.position = transform.position;
             prop.transform.rotation = transform.rotation;
 
             prop.PickUp(this);
             puppetMaster.AddMuscle(prop.muscle, prop.transform, connectTo, transform, prop.muscleProps, false, prop.forceLayers);
 
             if (prop.additionalPin != null && prop.additionalPinTarget != null)
             {
                 puppetMaster.AddMuscle(prop.additionalPin, prop.additionalPinTarget, prop.muscle.GetComponent<Rigidbody>(), prop.transform, new Muscle.Props(prop.additionalPinWeight, 0f, 0f, 0f, false, Muscle.Group.Prop), true, prop.forceLayers);
             }
         }
         void Aim()
         { Debug.Log("IsAiming");
             if (Input.GetMouseButtonDown(0))
             { Throw(); }
                 }
         void Throw()
         {
 
             
             Debug.Log("Boom");
             puppetMaster.RemoveMuscleRecursive(lastProp.muscle, true, false, MuscleRemoveMode.Sever);
             rb = currentProp.GetComponentInParent<Rigidbody>();
             rb.isKinematic = false;
             
             rb.AddForce(Camera.main.transform.forward * thrust,ForceMode.Impulse);
         }
     }
 }

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

0 Replies

· Add your reply
  • Sort: 

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.

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

183 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I mimic this game's camera in Unity? 1 Answer

I only rotated X, but Y and Z are shifting as well when I play the game. 1 Answer

Stop camera from going through walls 2 Answers

Moving 3rd person player relative to orbiting camera 1 Answer

Aiming with a third person camera/positioning a third person camera 3 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