Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by Feteo · Mar 26, 2021 at 01:41 PM · unity 2dweaponhitpick up object

Unity 2D Weapon Pick Up And Striking/Swinging

I think my question is pretty straightforward: You have the player and some objects containing my own script "Throwable". In my case beer bottles.

Image of Beer Bottles And Player

I already got the player to pick up those bottles and throw them. The center of the "InteractionPoint"(which is the white circle with the crossing diameters) is the position, where the bottles will be "held" once picked up. My script looks like this:

     public bool PickUp(GameObject attachedTo)
     {
         gameObject.transform.parent = attachedTo.transform; // Add to parent
         gameObject.transform.localPosition = attachedTo.transform.Find("InteractionPoint").localPosition; // Set position
         m_collisionpoints.enabled = false; // no collision
         m_Rigidbody2D.isKinematic = true; // no gravity 
         m_Rigidbody2D.velocity = new Vector2(0f, 0f); // no velocity
         m_Rigidbody2D.angularVelocity = 0f; // no rotation
         PickedUp(true, attachedTo); // picked up and parent
         return true;
     }

That works and looks like this: Picked Up Beer Bottle Now throwing isn't too bad either, just revert those manipulations done on the RigidBody and add a force to it, which also works fine. But I also want the player to be able to strike with the bottle. Maybe hold it upside down and attack with it. And this is where my problem lies: I have no idea how to tackle that idea.

Suppose we have a 2d animated frame-by-frame sprite and the interaction point is basically his "hand". I don't know where to start. Should it be an animation? Should I just script the InteractionPoint moving somewhere? How can I "swing" the bottle? As is it looks rather static, being fixed to the interaction point.

unity-beerbottles-1.png (67.2 kB)
unity-beerbottles-2.png (8.4 kB)
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 Feteo · Apr 03, 2021 at 09:20 AM 0
Share

OK, I'm making a little bit of progress here, but not really. Once my character picks up a bottle, it becomes his child object. I can animate that child object, but my problem is, that I want this to be as general as possible. I don't know, what kind of object the player will hold and my animation clip needs to be applicable to other kind of child objects as well.

1 Reply

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

Answer by Tom4nt · Apr 03, 2021 at 11:02 AM

If I understand your situation correctly, I think the following solution would work for you:

Try to add an intermediate object (a pivot) to the InteractionPoint object. Then, you can animate the position, rotation and scale (if needed) of the pivot and it will animate relative to it's parent (InteractionPoint).

After that, at runtime, you can just parent the bottle or any other throwable to the pivot object and it will move/rotate/scale with it.

Let me know if I misunderstood your problem.

Sorry for any English mistake.

Comment
Add comment · Show 2 · 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 Feteo · Apr 06, 2021 at 04:02 PM 0
Share

This helped a lot. Thank you.

avatar image Tom4nt Feteo · Apr 06, 2021 at 04:03 PM 0
Share

Glad I could help :)

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

119 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

Related Questions

,Trying to flip a sprite to the left from the right side with a mouse 0 Answers

My script for grabbing and carrying objects in 2D doesn't work properly. 2 Answers

Detect Shield Mesh Sides Hit 1 Answer

instantiate decal at raycastHit 1 Answer

How can I blink a gameobject faster and faster? 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