- Home /
C# RotateAround Half Circle Instead of Full Circle
I've been working on a melee weapon script which rotates a weapon gameobject around the player upon mouse click. Is there anyway to restrict transform.RotateAround so that the weapon gameobject only rotates half a circle in front of the player? Right now my script has the weapon gameobject RotateAround the player fully and I want the weapon script to stay in front of the player.
using UnityEngine;
using System.Collections;
public class MeleeRotateAround : MonoBehaviour {
public Transform player;
public Vector3 nextWeaponPos;
public bool isSwinging;
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(0)){
isSwinging = true;
nextWeaponPos = -transform.position;
}
if(isSwinging){
if(transform.position != nextWeaponPos){
transform.RotateAround(player.position, Vector3.forward, 1);
}
else if(transform.position != nextWeaponPos){
isSwinging = false;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Rotate around moves object out of position, why? 1 Answer
Multiple Cars not working 1 Answer
Rotate object around object with fixed value. 1 Answer
How can i set a radius for rotatearound ? 0 Answers
RotateAround Limitations 2 Answers