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.GetKeyDown(KeyCode.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 ); }

3 Answers

3

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

// 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;

there is no "Constant force" attached to the object

any help is appreciated

The solution:

if(Input.GetKey(KeyCode.Alpha1)){
				
			transform.Rotate (Vector3.up, speed * Time.deltaTime);
				if(speed<4000)
				speed+=1.0f;
			}