Snake MOVEMENT (snake vs block) HELP!!!
Hi everyone, i have a problem with my snake movement like in Snake vs Blocks. I use 2 type of movement by accelerometer is perfect ma with finger not. Thanks to everyone than can help me. I would like a movement like in Snake vs Block. Also when i move snake with my sister the snake go trough cube or blocks sometimes, when the velocity is high.
public class PallinaMovement : MonoBehaviour {
public float pallinaSpeedX;
public float pallinaSpeedY;
//punto finale dello schermo cliccato
public Vector3 endPos;
public Vector3 startPos;
public static PallinaMovement pallinaMovement;
GameObject particles;
void Awake(){
if (pallinaMovement == null) {
pallinaMovement = this;
}
}
void Start () {
SalvataggioNUOVO.control.Load ();
pallinaSpeedX = 3.0f;
pallinaSpeedY = 0.05f;
}
void FixedUpdate () {
if (SalvataggioNUOVO.control.isAccelerometerEnable == false) {
TouchAxisMove();
}
if (SalvataggioNUOVO.control.isAccelerometerEnable == true) {
AccelerometerMove ();
}
}
void AccelerometerMove(){
pallinaSpeedX = 5;
float x = Input.acceleration.x;
if (x < -0.1f) {
MoveLeft ();
} else if (x > 0.1f) {
MoveRight ();
} else {
SetVelocityZero ();
}
}
void TouchMove()
{ pallinaSpeedX = 3;
if (Input.touchCount >= 1)
{
Touch touch = Input.GetTouch(0);
float middle = Screen.width / 2;
if (touch.position.x < middle)
{
MoveLeft();
}
else if (touch.position.x > middle)
{
MoveRight();
}
}else{
SetVelocityZero();
}
}
void TouchAxisMove(){
pallinaSpeedX = 3f;
if (Input.touchCount >= 1 && Input.GetTouch(0).phase == TouchPhase.Began) {
startPos = Camera.main.ScreenToWorldPoint (new Vector3 (Input.GetTouch (0).position.x, 0, 0));
SetVelocityZero ();
}
if(Input.touchCount >= 1 && Input.GetTouch(0).phase == TouchPhase.Moved){
endPos = Camera.main.ScreenToWorldPoint (new Vector3 (Input.GetTouch (0).position.x, 0, 0));
float a = (endPos.x - startPos.x);
gameObject.transform.position += new Vector3(a/50 ,pallinaSpeedY,0);
ManageGame.manageGame.isMoving = true;
} else {
ManageGame.manageGame.isMoving = false;
SetVelocityZero ();
}
}
public void MoveLeft()
{
gameObject.transform.position += new Vector3(-0.03f,pallinaSpeedY,0);
}
public void MoveRight()
{
gameObject.transform.position += new Vector3(0.03f,pallinaSpeedY,0);
}
public void SetVelocityZero()
{
gameObject.transform.position += new Vector3(0,pallinaSpeedY,0);
}
void OnCollisionEnter2D(Collision2D coll){
if (coll.gameObject.tag == "RomboNormale") {
SalvataggioNUOVO.control.monete += 1;
SalvataggioNUOVO.control.Save ();
ManageGame.manageGame.moneteGameplay.text = SalvataggioNUOVO.control.monete.ToString ();
ManageGame.manageGame.romboEffettoCoins.gameObject.SetActive (true);
ManageGame.manageGame.romboSpecialeEffettoCoins.gameObject.SetActive (false);
Invoke ("Disable", 1.5f);
Destroy (coll.gameObject);
}
if (coll.gameObject.tag == "RomboSpeciale") {
SalvataggioNUOVO.control.monete += 10;
SalvataggioNUOVO.control.Save ();
ManageGame.manageGame.romboSpecialeEffettoCoins.gameObject.SetActive (true);
ManageGame.manageGame.romboEffettoCoins.gameObject.SetActive (false);
Invoke ("Disable", 1.5f);
Destroy (coll.gameObject);
}
}
public void Disable(){
ManageGame.manageGame.romboSpecialeEffettoCoins.gameObject.SetActive (false);
ManageGame.manageGame.romboEffettoCoins.gameObject.SetActive (false);
}
}
Comment
Your answer
Follow this Question
Related Questions
Post time at the end of the level 0 Answers
How to detect the touch on certain Game Object (UI Panel) 1 Answer
How can I have Unity display the correct tiles based on their surrounding tiles (ie corners) 2 Answers
2DToolkit Sprites on Native UI Canvas 0 Answers
Remove button OnMouseOver highlighting 0 Answers