- Home /
Spinning attack!
So, I've created an animation of my character putting his sword straight out. Now, I want to spin the character until the player releases the button... The position should be reset when the button is let go (getkeyup(keycode.alpha1) would be used here. The question is, how can i record all the player stats before I go into the rotation and also how Will I rotate the player? I just finished solving a huge problem and tbh am a little lazy to look in this moment. Of course, as always if nobody wishes to respond i'll keep digging.
if(Input.GetKey(KeyCode.Alpha1))
{
Debug.Log ("Should Be Skill Attacking");
animation.Play ("skillAttack");
}
I am having no luck... The below script does nothing.
void Update () {
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Alpha1))
constantForce.relativeTorque = Vector3.right * 2;
//transform.Rotate(Vector3.right, constantForce.relativeTorque * Time.deltaTime);
// transform.rotation = Quaternion.Euler ( transform.rotation.x++, transform.rotation.y, transform.rotation.z );
}
Answer by KuPAfoo · Dec 21, 2013 at 09:37 PM
The solution:
if(Input.GetKey(KeyCode.Alpha1)){
transform.Rotate (Vector3.up, speed * Time.deltaTime);
if(speed<4000)
speed+=1.0f;
}
Answer by Benproductions1 · Dec 21, 2013 at 09:04 AM
Hello,
The character rotation should probably be an animation, not something you calculate at runtime, while keeping track of the position is easy:
//UnityScipt
private var attackStartPosition:Vector3;
function StartAttack() {
attackStartPosition = transform.position;
}
function StopAttack() {
transform.position = attackStartPosition;
}
//C#
Vector3 attackStartPosition;
public void StartAttack() {
attackStartPosition = transform.position;
}
public void StopAttack() {
transform.position = attackStartPosition;
}
Hope this helps,
Benproductions1
Hmm... I was trying to animate the rotation in blender but it wouldn't rotate properly.. It would rotate clockwise 12o'clock, 6 o'clock, counterclockwise 12 o'clock. Even if it was animated as 12 o'clock 3 o'clock 6 o'clock when trying to animate to 9 o'clock it would counter-rotate back past 3o'clock into 12 o'clock then 9 o'clock...
The above reelwirax's suggestion is kind-of panning out... I had to find the proper file that was constantly setting the player's rotation. Now that i've located it, I've found that this rotates the player forward:
if (IsGrounded())
{
if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.Alpha1))
transform.Rotate (Vector3.right, speed * Time.deltaTime);
else
transform.rotation = Quaternion.LookRotation(moveDirection);
}
Answer by reefwirrax · Dec 16, 2013 at 01:54 AM
// Rotates the object around the its own x-axis
constantForce.relativeTorque = Vector3.right * 2;
I'm running into errors that brought me to documentation saying use "addForce" and that makes a certain child object move, not rotate :\
This appears to be working the best, however it only points my character to the right :\
moveDirection = Vector3.right;
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Rotating a 2D object when the phone is rotated 1 Answer
Character Controller slides sideways when it hits objects are angles different from 90 degrees 1 Answer
Move and Rotate object with "Parent" without Parenting 1 Answer
Rotating a rigidbody on mouse click. 1 Answer