mirror of
https://github.com/ConjureETS/PixelSphinx.git
synced 2026-03-25 11:00:59 +00:00
Pushing wedges forth and back. (need to adjust planet radius with offest)
This commit is contained in:
parent
c19b71cfa8
commit
1fefe8e788
@ -23,15 +23,16 @@ public class PlanetManager : MonoBehaviour
|
|||||||
{
|
{
|
||||||
float debutAngleTheta = i* TailleCartiersEnDegres;
|
float debutAngleTheta = i* TailleCartiersEnDegres;
|
||||||
var w = new Wedge() {tMin = debutAngleTheta, tMax = debutAngleTheta + TailleCartiersEnDegres};
|
var w = new Wedge() {tMin = debutAngleTheta, tMax = debutAngleTheta + TailleCartiersEnDegres};
|
||||||
wedges.Add(w); //pushes at end.
|
|
||||||
|
|
||||||
//float angle = i * Mathf.PI * 2 / NbCartiers * 360;
|
//float angle = i * Mathf.PI * 2 / NbCartiers * 360;
|
||||||
var wedgePos = GetPlanetCoordinatesFromPlayerXY(debutAngleTheta, 0);
|
var wedgePos = GetPlanetCoordinatesFromPlayerXY(debutAngleTheta, 0);
|
||||||
wedgePos.x -= 8/ Mathf.PI * Mathf.Cos(debutAngleTheta * Mathf.PI / 180);
|
wedgePos.x -= 8/ Mathf.PI * Mathf.Cos(debutAngleTheta * Mathf.PI / 180);
|
||||||
wedgePos.y -= 8/ Mathf.PI * Mathf.Sin(debutAngleTheta * Mathf.PI / 180);
|
wedgePos.y -= 8/ Mathf.PI * Mathf.Sin(debutAngleTheta * Mathf.PI / 180);
|
||||||
Instantiate(WedgePrefab, wedgePos, Quaternion.Euler(0, 0, debutAngleTheta));
|
var obj = Instantiate(WedgePrefab, wedgePos, Quaternion.Euler(0, 0, debutAngleTheta));
|
||||||
|
obj.name = "wedge_" + i;
|
||||||
|
w.sprite = GameObject.Find(obj.name);
|
||||||
|
wedges.Add(w); //pushes at end.
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -54,6 +55,55 @@ public class PlanetManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void PushWedge(float thetaPlayerX)
|
||||||
|
{
|
||||||
|
var index = GetWedgeIndex(thetaPlayerX);
|
||||||
|
var w = wedges[index];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
w.offset = w.offset - 0.5f;
|
||||||
|
if (w.offset < -1.0f)
|
||||||
|
w.offset = -1.0f;
|
||||||
|
|
||||||
|
var angle = w.tMin; //w.tMax - TailleCartiersEnDegres/2;
|
||||||
|
|
||||||
|
var normalPos = GetPlanetCoordinatesFromPlayerXY(angle, 0);
|
||||||
|
normalPos.x -= 8 / Mathf.PI * Mathf.Cos(angle * Mathf.PI / 180);
|
||||||
|
normalPos.y -= 8 / Mathf.PI * Mathf.Sin(angle * Mathf.PI / 180);
|
||||||
|
|
||||||
|
var wedgePos = GetPlanetCoordinatesFromPlayerXY(angle, 0);
|
||||||
|
wedgePos.x -= 8 / Mathf.PI * Mathf.Cos(angle * Mathf.PI / 180) - 50 * w.offset * Mathf.Cos(angle * Mathf.PI / 180);
|
||||||
|
wedgePos.y -= 8 / Mathf.PI * Mathf.Sin(angle * Mathf.PI / 180) - 50 * w.offset * Mathf.Sin(angle * Mathf.PI / 180);
|
||||||
|
|
||||||
|
|
||||||
|
w.sprite.transform.position = Vector3.Lerp(normalPos, wedgePos, Time.deltaTime);
|
||||||
|
|
||||||
|
///push back l'opposée
|
||||||
|
var indexOppose = GetWedgeOpposé(index);
|
||||||
|
var v = wedges[indexOppose];
|
||||||
|
|
||||||
|
v.offset = v.offset + 0.5f;
|
||||||
|
if (v.offset > 1.0f)
|
||||||
|
v.offset = 1.0f;
|
||||||
|
|
||||||
|
angle = v.tMin; //w.tMax - TailleCartiersEnDegres/2;
|
||||||
|
|
||||||
|
normalPos = GetPlanetCoordinatesFromPlayerXY(angle, 0);
|
||||||
|
normalPos.x -= 8 / Mathf.PI * Mathf.Cos(angle * Mathf.PI / 180);
|
||||||
|
normalPos.y -= 8 / Mathf.PI * Mathf.Sin(angle * Mathf.PI / 180);
|
||||||
|
|
||||||
|
wedgePos = GetPlanetCoordinatesFromPlayerXY(angle, 0);
|
||||||
|
wedgePos.x -= 8 / Mathf.PI * Mathf.Cos(angle * Mathf.PI / 180) - 50 * v.offset * Mathf.Cos(angle * Mathf.PI / 180);
|
||||||
|
wedgePos.y -= 8 / Mathf.PI * Mathf.Sin(angle * Mathf.PI / 180) - 50 * v.offset * Mathf.Sin(angle * Mathf.PI / 180);
|
||||||
|
|
||||||
|
|
||||||
|
v.sprite.transform.position = Vector3.Lerp(normalPos, wedgePos, Time.deltaTime);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Radius sphere est scale/2
|
/// Radius sphere est scale/2
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -110,7 +160,7 @@ public class PlanetManager : MonoBehaviour
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Wedge
|
public class Wedge
|
||||||
{
|
{
|
||||||
public float yoffset = 0; //valeurs entre -1 et 1; -1 étant renfoncé, 0 position normale, et 1 vers l'extérieur
|
public float offset = 0; //valeurs entre -1 et 1; -1 étant renfoncé, 0 position normale, et 1 vers l'extérieur
|
||||||
public float tMin = 0; //theta min et theta max : angle thetat de début et fin du cartier;
|
public float tMin = 0; //theta min et theta max : angle thetat de début et fin du cartier;
|
||||||
public float tMax = 0;
|
public float tMax = 0;
|
||||||
|
|
||||||
|
|||||||
92
Assets/Scripts/TimerFunctionsClass.cs
Normal file
92
Assets/Scripts/TimerFunctionsClass.cs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class TimerFunctionsClass : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
|
public delegate void OnTimerEvent(); //delegate type definition
|
||||||
|
|
||||||
|
private OnTimerEvent CallBackFunction; // the function that is called when the time is up
|
||||||
|
private float OriginalTimeInterval; // used for resetting
|
||||||
|
private float TimeLeft; // used for counting down
|
||||||
|
private bool Active = false;
|
||||||
|
|
||||||
|
protected bool DestroyTimerOnTimeEnds = false;
|
||||||
|
|
||||||
|
public string textTime = "";
|
||||||
|
|
||||||
|
|
||||||
|
public float GetTimeLeft()
|
||||||
|
{
|
||||||
|
return TimeLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup the timer: how long should the timer wait and which function should it call when the event is triggered
|
||||||
|
public void SetTimer(float TimeInterval, OnTimerEvent NewCallBackFunction)
|
||||||
|
{
|
||||||
|
OriginalTimeInterval = TimeInterval;
|
||||||
|
TimeLeft = TimeInterval;
|
||||||
|
CallBackFunction = NewCallBackFunction;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// actually start the timer:
|
||||||
|
public void StartTimer()
|
||||||
|
{
|
||||||
|
Active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// I'm not using this, but whatever:
|
||||||
|
public void StopTimer()
|
||||||
|
{
|
||||||
|
Active = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ohwell
|
||||||
|
public void ResetTimer()
|
||||||
|
{
|
||||||
|
TimeLeft = OriginalTimeInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void DestroyTimer()
|
||||||
|
{
|
||||||
|
Destroy(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TimeLeft is decreased by Time.deltaTime every tick, if it hits 0 then the CallBackFunction is called
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (Active)
|
||||||
|
{
|
||||||
|
|
||||||
|
TimeLeft -= Time.deltaTime;
|
||||||
|
if (TimeLeft <= 0)
|
||||||
|
{
|
||||||
|
CallBackFunction();
|
||||||
|
|
||||||
|
|
||||||
|
//si usage unique
|
||||||
|
if (DestroyTimerOnTimeEnds)
|
||||||
|
{
|
||||||
|
StopTimer();
|
||||||
|
DestroyTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
12
Assets/Scripts/TimerFunctionsClass.cs.meta
Normal file
12
Assets/Scripts/TimerFunctionsClass.cs.meta
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ba34cb3424d86984e882e8e209276792
|
||||||
|
timeCreated: 1460097512
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -4,15 +4,52 @@ using System.Collections;
|
|||||||
|
|
||||||
public class testRotate : MonoBehaviour {
|
public class testRotate : MonoBehaviour {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public float fireRate = 1.0f;
|
||||||
|
private float lastShot = 0.0f;
|
||||||
|
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if(Input.GetKeyDown("space") || Input.GetKey("s"))
|
||||||
|
{
|
||||||
|
|
||||||
|
Fire();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Fire()
|
||||||
|
{
|
||||||
|
if (Time.time > fireRate + lastShot)
|
||||||
|
{
|
||||||
|
lastShot = Time.time;
|
||||||
|
|
||||||
|
var speed = 13.2f;
|
||||||
|
var theta = Time.realtimeSinceStartup * speed % 360.0f;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var pmgr = FindObjectOfType<PlanetManager>();
|
||||||
|
pmgr.PushWedge(theta);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var index = pmgr.GetWedgeIndex(theta);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start () {
|
void Start () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update () {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Juste pour tester le mouvement du player autour du cercle.
|
/// Juste pour tester le mouvement du player autour du cercle.
|
||||||
@ -21,18 +58,18 @@ public class testRotate : MonoBehaviour {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void FixedUpdate()
|
void FixedUpdate()
|
||||||
{
|
{
|
||||||
var speed = 13.2;
|
var speed = 13.2f;
|
||||||
var theta = Time.realtimeSinceStartup * speed % 360.0; // Position X du player = angle theta
|
var theta = Time.realtimeSinceStartup * speed % 360.0f; // Position X du player = angle theta
|
||||||
var r = 5.0; //sphereradius
|
var r = 4.5f; //sphereradius
|
||||||
|
|
||||||
|
|
||||||
// XY coordinates
|
// XY coordinates
|
||||||
double x = r * Math.Cos(theta * Math.PI / 180);
|
var x = r * Mathf.Cos(theta * Mathf.PI / 180);
|
||||||
double y = r * Math.Sin(theta * Math.PI / 180); // + y0 du player
|
var y = r * Mathf.Sin(theta * Mathf.PI / 180); // + y0 du player
|
||||||
|
|
||||||
var player = GameObject.Find("CubePlayer").gameObject;
|
var player = GameObject.Find("CubePlayer").gameObject;
|
||||||
|
|
||||||
player.transform.position = Vector3.Lerp(player.transform.position, new Vector3( (float)x, (float)y, 0 ), Time.deltaTime);
|
player.transform.position = Vector3.Lerp(player.transform.position, new Vector3(x, y, 0 ), Time.deltaTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user