-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/SneakyRedSnake/rogue-shield …
…into dev
- Loading branch information
Showing
10 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
Assets/Prefab/Shield.prefab.meta → ...ts/Prefab/CharacterWithShield.prefab.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.