Donc je me demandait si il y avait quelques choses a savoir ou si je faisais les choses pas comme il faut !
Coté Main.
Code : Tout sélectionner
public class BoatMouvement : MonoBehaviour {
//déclaration de mes propres variables
public float Velocity;
public static float BoatDirection, BoatRotation,BoatDirectionTemp, xSpeed , ySpeed, JumpVelocity;
public float Turnspeed, CoefRotation,CoefFrottement,Gravity,NewScaler, StartJumpVelocity;
Vector3 GetKey,SetMouvement,SetScale;
public static Quaternion targetRotation;
public bool IsBoatJumping;
public static bool IsTurboAvaible;
public static int TurboCount;
public static List<float> GhostX;
public static List<float> GhostY;
public static List<float> GhostScale;
public static List<float> GhostRotation;
// Procédure qui récupére les valeur des touches
void GetInput()
{
GetKey.x = Input.GetAxisRaw("Horizontal");
GetKey.y = Input.GetAxisRaw("Vertical");
GetKey.z = 0.0f;
if (Mathf.Abs(GetKey.x) > 0)
{
BoatRotation -= Turnspeed * GetKey.x;
//BoatRotation = BoatRotation % 360;
}
if (GetKey.y > 0)
{
ySpeed += Mathf.Cos(BoatDirection * Mathf.Deg2Rad) * Velocity * Time.deltaTime;
xSpeed += Mathf.Sin(BoatDirection * Mathf.Deg2Rad) * Velocity * Time.deltaTime;
}
if (Input.GetKeyDown("space")){
if (!IsBoatJumping)
{
IsBoatJumping = true;
JumpVelocity = StartJumpVelocity;
}
}
if (IsBoatJumping)
{
JumpVelocity -= Gravity;
NewScaler += (JumpVelocity / 120);
if (NewScaler < 0.8f)
{
IsBoatJumping = false;
JumpVelocity = 0;
NewScaler = 0.8f;
}
}
BoatRotation *= CoefRotation;
BoatDirectionTemp = BoatDirection + (BoatRotation / 8);
xSpeed *= CoefFrottement;
ySpeed *= CoefFrottement;
targetRotation = Quaternion.Euler(0, 0, BoatDirectionTemp);
//transform.rotation = targetRotation;
BoatDirection = BoatDirectionTemp;
SetMouvement.x = -xSpeed;
SetMouvement.y = ySpeed;
SetMouvement.z = 0.0f;
SetScale = new Vector3(NewScaler, NewScaler ,NewScaler);
transform.position += SetMouvement ;
transform.rotation = targetRotation;
transform.localScale = SetScale;
GhostScale.Add(NewScaler);
GhostX.Add(SetMouvement.x);
GhostY.Add(SetMouvement.y);
GhostRotation.Add(BoatDirectionTemp);
}
// Use this for initialization
void Start () {
//Init values
Velocity = 0.13f;
BoatRotation = 0;
BoatDirection = 0;
Turnspeed = 5;
CoefRotation =0.85f;
CoefFrottement = 0.97f;
IsBoatJumping = false;
JumpVelocity = 0;
NewScaler = 0.8f;
Gravity = 0.7f;
StartJumpVelocity = 12;
GhostX = new List<float>();
GhostY = new List<float>();
GhostScale = new List<float>();
GhostRotation = new List<float>();
}
// Update is called once per frame
void Update () {
if (!PauseManager.IsPauseOn)
{
GetInput();
}
if (StartLineManager.IsStartLinereach)
{
if (GhostX.Count > 1)
{
print(GhostX.Count);
}
GhostX.Clear();
GhostY.Clear();
GhostScale.Clear();
GhostRotation.Clear();
}
}
}
Code : Tout sélectionner
public class GhostBehavior : MonoBehaviour
{
public Vector3 SetMouvement, SetScale;
public Quaternion setRotation;
public int FrameCount;
public static List<float> GhostGhostX;
public static List<float> GhostGhostY;
public static List<float> GhostGhostScale;
public static List<float> GhostGhostRotation;
// Start is called before the first frame update
void Start()
{
SetMouvement = new Vector3(0.0f, 0.0f, 0.0f);
SetScale = new Vector3(0.8f, 0.8f, 0.8f);
FrameCount = 0;
GhostGhostX = new List<float>();
GhostGhostY = new List<float>();
GhostGhostScale = new List<float>();
GhostGhostRotation = new List<float>();
}
// Update is called once per frame
void Update()
{
FrameCount++;
if (StartLineManager.IsStartLinereach)
{
FrameCount = 0;
}
if (GhostGhostX.Count > 1 && FrameCount < GhostGhostX.Count)
{
SetMouvement.x = GhostGhostX[FrameCount]*0.8f;
SetMouvement.y = GhostGhostY[FrameCount]*0.8f;
SetMouvement.z = 0.0f;
SetScale.x = GhostGhostScale[FrameCount];
SetScale.y = GhostGhostScale[FrameCount];
SetScale.z = GhostGhostScale[FrameCount];
transform.position += SetMouvement;
transform.localScale = SetScale;
transform.rotation = Quaternion.Euler(0, 0, GhostGhostRotation[FrameCount]);
}
}
}