public void Awake() { HandleCollisions = true; State = new ControllerState2D(); _transform = transform; _localScale = transform.localScale; _boxCollider = GetComponent <BoxCollider2D>(); // Рассчитываем расстояние между "лучами" кожи. // по вертикали - 4 луча // по горизонтали - 8 лучей // длина коллайдера в зависимости от масштаба var colliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * SkinWidth); // что бы разбить коллайдер на 3 части нужно его длину разделить на 2 // так как крайние лучи на границах коллайдера то отнимаем и их длину // |______________| // || || || #region TODO // ТОDO: Проверить или // var colliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (TotalVerticalRays * SkinWidth); #endregion _horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1); // высота коллайдера в зависимости от масштаба (аналогично ширине) var colliderHeight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * SkinWidth); _verticalDistanceBetweenRays = colliderHeight / (TotalHorizontalRays - 1); }
public void Awake() { HandleCollisions = true; State = new ControllerState2D(); _transform = transform; _localScale = transform.localScale; _boxCollider = GetComponent <BoxCollider2D>(); PlatformMask |= OneWayPlatformMask; recalculateDistanceBetweenRays(); }
// METODOS public void Awake() { HandleCollisions = true; State = new ControllerState2D(); _transform = transform; _localScale = transform.localScale; _boxCollider = GetComponent<BoxCollider2D>(); var colliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * SkinWidth); _horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1); var colliderHight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * SkinWidth); _verticalDistanceBetweenRays = colliderHight / (TotalHorizontalRays - 1); }
public void Awake() { HandleCollisions = true; State = new ControllerState2D(); _boxCollider = GetComponent <BoxCollider2D>(); _localScale = transform.localScale; _transform = transform; var ColliderHeight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * SkinWidth);; var ColliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * SkinWidth);; _verticalDistanceBetweenRays = ColliderHeight / (TotalHorizontalRays - 1); _horizontalDistanceBetweenRays = ColliderWidth / (TotalVerticalRays - 1); }
// Use this for initialization void Start() { _Collider = GetComponent <BoxCollider2D>(); _ControllerState = new ControllerState2D(); _ControllerState.IsFacingRight = true; _transform = gameObject.transform; Velocity = Vector2.zero; _horizontalDistanceBetweenArrays = (_Collider.size.x - skinWidth * 2) / (verticalRays - 1); _verticalDistanceBetweenArrays = (_Collider.size.y - skinWidth * 2) / (horizontalRays - 1); calculateRayOrigins(); //GameObject.FindGameObjectWithTag("Manager").GetComponent<ActorManager>().Actors.Add(this); ActorManager.instance.Actors.Add(this); }
void Awake() { LoadParameters(); state = new ControllerState2D(); boxCollider = GetComponent <BoxCollider2D>(); Assert.IsNotNull(boxCollider); float colliderWidthNoSkin = boxCollider.size.x * Mathf.Abs(transform.localScale.x) - 2 * skinWidth; float colliderHeightNoSkin = boxCollider.size.y * Mathf.Abs(transform.localScale.y) - 2 * skinWidth; horizontalDistanceBetweenRays = colliderWidthNoSkin / (totalVerticalRays - 1); verticalDistanceBetweenRays = colliderHeightNoSkin / (totalHorizontalRays - 1); }
public void Awake() { State = new ControllerState2D(); _transform = transform; // aliasing to prevent built-in chain calls _localScale = transform.localScale; _boxCollider = GetComponent <BoxCollider2D>(); var colliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - 2 * SkinWidth; _horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1); var colliderHeight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y) - 2 * SkinWidth; _verticalDistanceBetweenRays = colliderHeight / (TotalHorizontalRays - 1); }
public void Awake() { HandleCollisions = true; State = new ControllerState2D(); _transform = transform; _localScale = transform.localScale; _boxCollider = GetComponent <BoxCollider2D>(); var colliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * SkinWidth); // absolute function accounts for when player is flipped and local scale is -1 _horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1); var colliderHeight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * SkinWidth); _verticalDistanceBetweenRays = colliderHeight / (TotalHorizontalRays - 1); } // end Awake
public void Awake() { HandleCollisions = true; State = new ControllerState2D(); _transform = transform; _localScale = transform.localScale; _boxCollider = GetComponent <BoxCollider2D>(); // ta reda på avståndet mellan arrayerna på objektet var colliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * SkinWidth); _horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1); var colliderHeight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * SkinWidth); _verticalDistanceBetweenRays = colliderHeight / (TotalHorizontalRays - 1); }
public void Awake() { CanJump = true; HandleCollisions = true; State = new ControllerState2D(); JumpForce = Parameters.BaseJumpSpeed; _transform = transform; _localScale = transform.localScale; _boxCollider = GetComponent <BoxCollider2D> (); _spriteRenderer = gameObject.GetComponent <SpriteRenderer> (); var ColliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * SkinWidth); _horizontalDistanceBetweenRays = ColliderWidth / (TotalVerticalRays - 1); var ColliderHeight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * SkinWidth); _verticalDistanceBetweenRays = ColliderHeight / (TotalHorizontalRays - 1); }
public void Awake() { HandleCollisions = true; State = new ControllerState2D(); _transform = transform; _localScale = transform.localScale; _boxCollider = GetComponent <BoxCollider2D>(); var colliderWith = _boxCollider.size.x * Mathf.Abs(transform.localScale.x); _horizontalDistanceBetweenRays = colliderWith / (TotalVericalRays - 1); var colliderHeight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y); _verticalDistanceBetweenRays = colliderHeight / (TotalHorizontalRays - 1); Debug.Log(string.Format("_verticalDistanceBetweenRays.x:{0}", _verticalDistanceBetweenRays)); }
public void Awake() { HandleCollisions = true; State = new ControllerState2D(); _transform = transform; _localScale = transform.localScale; transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z); // makes player start facing right _boxCollider = GetComponent <BoxCollider2D>(); var colliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * SkinWidth); // Abs() returns absolute value - required here because to flip // player the local scale in x is inverted to -ve. A -ve value here // will screw up the calculation so we need the abslute value _horizontalDistnaceBetweenRays = colliderWidth / (TotalHorizontalRays - 1); var colliderHeight = (_boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * SkinWidth)) / 2.3f; // FIX REQUIRED - see top of page _verticalDistanceBetweenRays = colliderHeight / (TotalVerticalRays - 1); }
// End Data Members -------------------------------------- // Methods ----------------------------------------------------------------- // ------------------------------------------------------- public void Awake() { // If handle collisions is true, we get to run physics code! HandleCollisions = true; // We need to check the state of the Controller, to check if it's colliding with anything State = new ControllerState2D(); // We store local references to transform, local scale and the collider to save memory _transform = transform; _localScale = transform.localScale; _boxCollider = GetComponent <BoxCollider2D>(); // The width of the collider, multipled by it's local scale, and with the skinwidth removed (for raycasting) var colliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * skinWidth); // The horizontal distance between the rays, we raycast across the entire surface. _horizontalDistanceBetweenRays = colliderWidth / (totalVerticalRays - 1); // As above, but for vertical raycasting var colliderHeight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * skinWidth); _verticalDistanceBetweenRays = colliderHeight / (totalHorizontalRays - 1); }
/// <summary> /// Inicjalizacja i ustawienie poczatkowych wartosci parametrow. /// <summary> public void Awake() { HandleCollisions = true; State = new ControllerState2D(); _transform = transform; _localScale = transform.localScale; _boxCollider = GetComponent <BoxCollider2D>(); /// Obliczenie rozmiarow boxu, ktory moze uczestniczyc w kolizjach /// z innymi brylami sztywnymi. Od wartosci odejmowane sa skiny, z ktorych /// wychodza promienie wykrywajace kolizje (skin to waska ramka wokol obiektu, /// istniejaca po wewnetrznej stronie obiektu, sluzaca do wykrywania kolizji). /// Nastepnie obliczane sa odstepy pomiedzy promieniami wykrywajacymi kolizje. var colliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * SkinWidth); _horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1); var colliderHeight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * SkinWidth); _verticalDistanceBetweenRays = colliderHeight / (TotalHorizontalRays - 1); }
public void Awake() { HandleCollisions = true; State = new ControllerState2D(); _transform = transform; _localScale = transform.localScale; _boxCollider = GetComponent <BoxCollider2D>(); var colliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * SkinWidth); _horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1); var colliderHeight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * SkinWidth); _verticalDistanceBetweenRays = colliderHeight / (TotalHorizontalRays - 1); //calcSlant(); //calcSudoTransform(); rotationVector = transform; calcSlant(); cfilter.layerMask = PlatformOnly; }
// Now our public methods - public APIs for manipulating how we want our player to move // The difference between Awake and Start is that Start is only called if the script instance is enabled. // This allows you to delay any initialization code, until it is really needed. // Awake is always called before any Start functions. This allows you to order initialization of scripts. // Think of Awake() as the script that does the heavy lifting so that Start() can hit the ground running. public void Awake() { State = new ControllerState2D(); _transform = transform; _localScale = _transform.localScale; _boxCollider = GetComponent<BoxCollider2D>(); //GetComponent allows us to use a type as a variable. // The width of the collider is the actual size of the box collider * the scaling of the // player which we may change minus (the skinwidth offset from the left side + the skinwidth offset from the right side) // We need to take the absolute value of the scale since flipping the player negates it. var colliderWidth = _boxCollider.size.x * Mathf.Abs(_transform.localScale.x) - (2 * SkinWidth); _horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1); var colliderHeight = _boxCollider.size.y * Mathf.Abs(_transform.localScale.y) - (2 * SkinWidth); _verticalDistanceBetweenRays = colliderHeight/ (TotalHorizontalRays - 1); }
public void Awake() { state = new ControllerState2D (); }
void Awake() { state=new ControllerState2D();// je dois instantiate state :) collider=GetComponent<BoxCollider2D>(); CalculateRaySpacing(); }
// Methods Begin public void Awake() { HandleCollisions = true; State = new ControllerState2D(); myTransform = transform; localScale = transform.localScale; boxCollider = GetComponent<BoxCollider2D>(); var colliderWidth = boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * SkinWidth); horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1); var colliderHeight = boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * SkinWidth); verticalDistanceBetweenRays = colliderHeight / (TotalHorizontalRays - 1); // Staff Awake StaffState = new StaffState2D(); staffPosition = PointDebugActive.transform.position; staffLocalScale = PointDebugActive.transform.localScale; staffBoxCollider = PointDebugActive.GetComponent<BoxCollider2D>(); var staffColliderWidth = staffBoxCollider.size.x * Mathf.Abs(staffLocalScale.x) - (2 * StaffSkinWidth); staffHorizontalDistanceBetweenRays = staffColliderWidth / (StaffTotalVerticalRays - 1); var staffColliderHeight = staffBoxCollider.size.y * Mathf.Abs(staffLocalScale.y) - (2 * StaffSkinWidth); staffVerticalDistanceBetweenRays = staffColliderHeight / (StaffTotalHorizontalRays - 1); }
// Inicjalizacja i ustawienie poczatkowych wartosci parametrow. public void Awake() { HandleCollisions = true; State = new ControllerState2D(); _transform = transform; _localScale = transform.localScale; _boxCollider = GetComponent<BoxCollider2D>(); // Obliczenie rozmiarow boxu, ktory moze uczestniczyc w kolizjach // z innymi brylami sztywnymi. Od wartosci odejmowane sa skiny, z ktorych // wychodza promienie wykrywajace kolizje (skin to waska ramka wokol obiektu, // istniejaca po wewnetrznej stronie obiektu, sluzaca do wykrywania kolizji). // Nastepnie obliczane sa odstepy pomiedzy promieniami wykrywajacymi kolizje. var colliderWidth = _boxCollider.size.x * Mathf.Abs(transform.localScale.x) - (2 * SkinWidth); _horizontalDistanceBetweenRays = colliderWidth / (TotalVerticalRays - 1); var colliderHeight = _boxCollider.size.y * Mathf.Abs(transform.localScale.y) - (2 * SkinWidth); _verticalDistanceBetweenRays = colliderHeight / (TotalHorizontalRays - 1); }
public void Awake() { State = new ControllerState2D(); }