Заключается она в том что при попытке сделать стрельбу через рейкаст в 2d платформере возникает проблема с направлением выпускаемого луча.
Уровень с персонажем находятся в отрицательных координатах по оси X и при выстреле направо проблем нет, но при отображении перса налево,как я понял,луч выпускается в направлении 0 координат оси прошу помощи, так как не совсем понимаю координаты 2d и только начал делать что то в unity на полноценном 2d.
Как я только не пытался, ничего не выходит(
Пример кода
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shot : MonoBehaviour {
public int movv;
public Vector2 vect_l;
public Vector2 vect_r;
void Start () {
vect_l = Vector2.left;
vect_r = Vector2.right;
}
void Update () {
//Отображение персонажа
movv=gameObject.GetComponentInParent<CharacterController> ().check;
}
public void Shoot(){
if (movv > 0) {
//направление вправо
RaycastHit2D hit = Physics2D.Raycast (this.gameObject.transform.position,vect_r);
Debug.DrawLine (this.gameObject.transform.position, hit.point, Color.red);
}
if(movv<0){
//направление влево
RaycastHit2D hit1 = Physics2D.Raycast (this.gameObject.transform.position,vect_l);
Debug.DrawLine (this.gameObject.transform.position, hit1.point, Color.red);
}
}
}
using System.Collections.Generic;
using UnityEngine;
public class Shot : MonoBehaviour {
public int movv;
public Vector2 vect_l;
public Vector2 vect_r;
void Start () {
vect_l = Vector2.left;
vect_r = Vector2.right;
}
void Update () {
//Отображение персонажа
movv=gameObject.GetComponentInParent<CharacterController> ().check;
}
public void Shoot(){
if (movv > 0) {
//направление вправо
RaycastHit2D hit = Physics2D.Raycast (this.gameObject.transform.position,vect_r);
Debug.DrawLine (this.gameObject.transform.position, hit.point, Color.red);
}
if(movv<0){
//направление влево
RaycastHit2D hit1 = Physics2D.Raycast (this.gameObject.transform.position,vect_l);
Debug.DrawLine (this.gameObject.transform.position, hit1.point, Color.red);
}
}
}