Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into dev
  • Loading branch information
Feinte75 committed Oct 17, 2015
2 parents 89cedd4 + 6d69caa commit 52d5a7c
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 5 deletions.
Binary file removed Assets/Prefab/Character with Shield.prefab
Binary file not shown.
4 changes: 0 additions & 4 deletions Assets/Prefab/Character with Shield.prefab.meta

This file was deleted.

Binary file added Assets/Prefab/CharacterWithShield.prefab
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed Assets/Prefab/Player.prefab
Binary file not shown.
Binary file removed Assets/Prefab/Shield.prefab
Binary file not shown.
33 changes: 33 additions & 0 deletions Assets/Scripts/RotateAroundPivot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using UnityEngine;
using System.Collections;

/// <summary>
/// Components to permits rotation of a game object in a specified angle
/// </summary>
public class RotateAroundPivot : MonoBehaviour {
[SerializeField] GameObject pivot;
[SerializeField] float rotateAngle;


// Use this for initialization
void Start () {
}

// Update is called once per frame
void Update () {

}

/// <summary>
/// Rotation under the z axes using Quaternion.Euler
/// </summary>
/// <param name="z">The angle with the z axes</param>
public void RotationZ(float z, float distOfPivot){
//We rotate the game object
transform.rotation = Quaternion.Euler(0,0,z);

//then we put it at the correct position
float rad = (z+rotateAngle) * Mathf.Deg2Rad;
transform.position = pivot.transform.position + distOfPivot * new Vector3(Mathf.Sin (rad), -Mathf.Cos (rad));
}
}
8 changes: 8 additions & 0 deletions Assets/Scripts/RotateAroundPivot.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions Assets/Scripts/ShieldControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using UnityEngine;
using System.Collections;

/// <summary>
/// The controller of the shield
/// </summary>
[RequireComponent(typeof(RotateAroundPivot))]
public class ShieldControl : MonoBehaviour {

private RotateAroundPivot rotateAround; //The component to do a rotation around sth
[SerializeField]float distShieldPlayer = 4; //The distance we want between the shield and the player

// Use this for initialization
void Start () {
rotateAround = GetComponent<RotateAroundPivot>();
}

// Update is called once per frame
void Update () {
//we get the position of the player
//TODO changer le GetChild en get player?
Vector3 pos = transform.parent.GetChild(0).position;

//we get the position of the camera relative at the current scene
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

//we calculate the angle
float deg = Mathf.Rad2Deg * Mathf.Atan2(mousePos.y - pos.y, mousePos.x - pos.x);

//we do a rotation
rotateAround.RotationZ (deg, distShieldPlayer);
}
}
8 changes: 8 additions & 0 deletions Assets/Scripts/ShieldControl.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 52d5a7c

Please sign in to comment.