Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
1
Question by PrimedAlpha · Mar 08, 2020 at 01:39 PM · weaponsword

Have a sword rotate around the player

Hello! I want to make something similar to Archvale's weapon rotation. Can you guys point me towards on how to acheive it? The rotation around the player, and the how the sword also responds to the rotation.

https://www.youtube.com/watch?v=hDxxKNS55Cg

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by JPaulBourque · Mar 27, 2020 at 10:26 PM

@PrimedAlpha I'm trying to achieve the same thing, and found this snip of code that gets us closer to the desired behavior... but I'm still trying to figure out how to get that excellent swinging animation and having the sword rendering on the "far" side of the player from the mouse... Good luck and let me know if this helps/if you find anything else!

 // Point you want to have sword rotate around
  public Transform shoulder;
  // how far you want the sword to be from point
  public float armLength = 1f;
  void Start() {
      // if the sword is child object, this is the transform of the character (or shoulder)
      shoulder = transform.parent.transform;
  }
  void Update() {
      // Get the direction between the shoulder and mouse (aka the target position)
      Vector3 shoulderToMouseDir = 
          Camera.main.ScreenToWorldPoint(Input.mousePosition) - shoulder.position;
      shoulderToMouseDir.z = 0; // zero z axis since we are using 2d
      // we normalize the new direction so you can make it the arm's length
      // then we add it to the shoulder's position
      transform.position = shoulder.position + (armLength * shoulderToMouseDir.normalized);
  }
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 PrimedAlpha · Aug 12, 2020 at 11:53 AM 1
Share

Thanks for the reply! :) Greatly appreciated! Well I have the "orbiting" part figured out. It was more the animation and the sword tiling which i was interested in. He game me an example of how the animation can be done: This is in gamemaker code btw.

///create event swipe = 1; swipeInterpolate = swipe;

///step event if(attack) { swipe *= -1; } swipeInterpolate = lerp(swipeInterpolate, swipe, 0.2);

///draw event var dir = point_direction(x, y, mouse_x, mouse_y) + swipeInterpolate * 180; // Change 180 to whatever you like var xx = lengthdir_x(10, dir); // Change 10, this is just distance the sword is away from the player var yy = lengthdir_y(10, dir); // ^^^ draw_sprite_ext(s_sword, 0, x + xx, y + yy, 1, 1, dir, c_white, 1);

Hope this helps! :) Sorry for the late reply

avatar image Box_Frog PrimedAlpha · Feb 02, 2021 at 12:45 AM 0
Share

Did you find a way to get this to work well in unity?

avatar image
0

Answer by streeetwalker · Mar 26, 2020 at 06:31 PM

@PrimedAlpha, They're probably using an animation track to do that.

I am not familiar enough with those, but you'd do well do check that out - it's probably the best way to do it:

https://docs.unity3d.com/Manual/AnimationOverview.html There are tons of videos tutorials on youTube.

Comment
Add comment · Show 1 · 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 PrimedAlpha · Aug 12, 2020 at 11:50 AM 0
Share

I reached out to the developer and found out it was all through code. Sorry for the late reply. Once again thanks for the reply! :)

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

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

3rd person weapon equiping 1 Answer

Put all info from one game object to another one 0 Answers

(Vive Question) How do I snap a sword to the right position and rotation? 0 Answers

Weapon Switch 0 Answers

Rotate weapon with the crossair and cursor lock 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