mirror of
https://github.com/ConjureETS/PixelSphinx.git
synced 2026-03-24 02:20:58 +00:00
première ébauche PlanetManager
This commit is contained in:
parent
5546304506
commit
ef07f70d65
93
Assets/Scripts/PlanetManager.cs
Normal file
93
Assets/Scripts/PlanetManager.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class PlanetManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public int NbCartiers = 10;
|
||||
public float TailleCartiersEnDegres = 0; //radian -> valeurs 0 a 360
|
||||
|
||||
var wedges = new List<Wedge>();
|
||||
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
TailleCartiersEnRadiants = 360.0 / NbCartiers;
|
||||
|
||||
float debutAngleTheta = 0.0;
|
||||
|
||||
for(int i = 0; i < NbCartiers; i++)
|
||||
{
|
||||
debutAngleTheta = i*TailleCartiersEnRadiants;
|
||||
wedges.Add(new wedges(){tMin = debutAngleTheta, tMax = debutAngleTheta + TailleCartiersEnRadiants});
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public float GetPlanetRadius()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Vector3 GetPlanetCoordinatesFromPlayerXY(float playerLocalX, float playerLocalY)
|
||||
{
|
||||
var theta = playerLocalX;
|
||||
double x = r * Math.Cos(theta * Math.PI / 180);
|
||||
double y = r * Math.Sin(theta * Math.PI / 180) + playerLocalY;
|
||||
|
||||
|
||||
return new Vector3(x,y,0);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// retourn le no de plateforme
|
||||
/// </summary>
|
||||
/// <param name="thetaPlayerX"></param>
|
||||
public int GetWedgeIndex(float thetaPlayerX)
|
||||
{
|
||||
return Math.Floor(thetaPlayerX / TailleCartiersEnRadiants);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="wedgeIndex"></param>
|
||||
/// <returns></returns>
|
||||
public int GetWedgeOpposé(int wedgeIndex)
|
||||
{
|
||||
//(i + 5) % 10 => [0,9]
|
||||
return (wedgeIndex + NbCartiers / 2) % (NbCartiers);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// retourne l'objet interne
|
||||
/// </summary>
|
||||
/// <param name="thetaPlayerX"></param>
|
||||
/// <returns></returns>
|
||||
public Wedge GetWedgeFromTheta(float thetaPlayerX)
|
||||
{
|
||||
return wedges[GetWedgeIndex(thetaPlayerX)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Représente une plateforme qui bouge.
|
||||
/// </summary>
|
||||
public class Wedge
|
||||
{
|
||||
float yoffset = 0; //valeurs entre -1 et 1; -1 étant renfoncé, 0 position normale, et 1 vers l'extérieur
|
||||
float tMin = 0; //theta min et theta max : angle thetat de début et fin du cartier;
|
||||
float tMax = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
38
Assets/Scripts/testRotate.cs
Normal file
38
Assets/Scripts/testRotate.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class testRotate : MonoBehaviour {
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Juste pour tester le mouvement du player autour du cercle.
|
||||
/// Le player se déplace de gauche a droite en x et la valeur de x représente l'angle theta
|
||||
/// saute en y
|
||||
/// </summary>
|
||||
void FixedUpdate()
|
||||
{
|
||||
var speed = 13.2;
|
||||
var theta = Time.realtimeSinceStartup * speed % 360.0; // Position X du player = angle theta
|
||||
var r = 5.0; //sphereradius
|
||||
|
||||
|
||||
// XY coordinates
|
||||
double x = r * Math.Cos(theta * Math.PI / 180);
|
||||
double y = r * Math.Sin(theta * Math.PI / 180); // + y0 du player
|
||||
|
||||
var player = GameObject.Find("CubePlayer").gameObject;
|
||||
|
||||
player.transform.position = Vector3.Lerp(player.transform.position, new Vector3( (float)x, (float)y, 0 ), Time.deltaTime);
|
||||
|
||||
}
|
||||
}
|
||||
BIN
Assets/_Scenes/planet.unity
Normal file
BIN
Assets/_Scenes/planet.unity
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user