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.
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);
}
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
Did you find a way to get this to work well in unity?
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.
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
Follow this Question
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