public void GetInterpolateValues() { if (PositionChanged) { lastPos = curPos; curPos = Position.ToVector3(transform.position.y); PositionChangedBuffer = true; } if (RotationChanged) { lastRot = curRot; curRot = Rotation.ToVector3(0f); RotationChangedBuffer = true; } }
public void Teleport(Vector2d destination) { this.Position = destination; this.visualPosition = destination.ToVector3(visualPosition.y); this.lastVisualPos = visualPosition; this._positionalTransform.position = visualPosition; }
public void Visualize () { if (SetPositionBuffer) { this.cachedTransform.position = Position.ToVector3 (transform.position.y); SetPositionBuffer = false; } if (SetRotationBuffer) { this.cachedTransform.rotation = Quaternion.LookRotation (Rotation.ToVector3 (0f)); SetRotationBuffer = false; } }
public void SetVisuals() { if (this.SetVisualPosition) { DoSetVisualPosition( _position.ToVector3(HeightPos.ToFloat()) ); } if (this.SetVisualRotation) { this.DoSetVisualRotation(_rotation); } }
// Update is called once per frame void FixedUpdate() { if (!m_bArrived) { if (!m_bFindPath) { m_MyPath.FastClear(); StartPos = new Vector2d(FixedMath.Create(transform.position.x), FixedMath.Create(transform.position.z)); EndPos = new Vector2d(FixedMath.Create(m_Destination.x), FixedMath.Create(m_Destination.z)); if (m_Blocker) { m_Blocker.RemoveAllCoordinates(); } ++m_SearchCount; if (Pathfinder.FindPath(StartPos, EndPos, m_MyPath)) { m_Index = 0; m_bFindPath = true; m_bArrivedMiddle = true; } else { m_bFindPath = false; m_bArrived = true; } if (m_Blocker) { m_Blocker.ReAddAllCoordinates(); } } if (m_bFindPath) { if (m_Index < m_MyPath.Count) { if (m_bArrivedMiddle) { m_Target = m_MyPath[m_Index]; ++m_Index; m_bArrivedMiddle = false; m_TargetPos = m_Target.ToVector3(transform.position.y); transform.LookAt(m_TargetPos); //GetComponent<Rigidbody>().velocity = transform.forward * 10; m_CurDis = Vector2.Distance(transform.position, m_TargetPos); m_LastDis = m_CurDis + 1.0f; } } } } }
public void Initialize(Vector2d StartPosition, Vector2d StartRotation) { Parent = null; PositionChanged = true; RotationChanged = true; VelocityChanged = true; PositionChangedBuffer = false; RotationChangedBuffer = false; Priority = _priority; Velocity = Vector2d.zero; VelocityFastMagnitude = 0; Position = StartPosition; Rotation = StartRotation; _parent = null; LocalPosition = Vector2d.zero; LocalRotation = Vector2d.up; XMin = 0; XMax = 0; YMin = 0; YMax = 0; PastGridXMin = long.MaxValue; PastGridXMax = long.MaxValue; PastGridYMin = long.MaxValue; PastGridYMax = long.MaxValue; if (Shape != ColliderType.None) { BuildPoints(); BuildBounds(); } ID = PhysicsManager.Assimilate(this); Partition.PartitionObject(this); visualPosition = Position.ToVector3(0f); lastVisualPos = visualPosition; _positionalTransform.position = visualPosition; visualRot = Quaternion.LookRotation(Rotation.ToVector3(0f)); lastVisualRot = visualRot; _positionalTransform.rotation = visualRot; }
public void SetVisuals() { if (this.SetVisualPosition) { DoSetVisualPosition( _position.ToVector3(HeightPos.ToFloat()) ); PositionalTransform.position = Vector3.SmoothDamp(lastVisualPos, _visualPosition, ref velocityPosition, PhysicsManager.LerpTime); } if (this.SetVisualRotation) { this.DoSetVisualRotation(_rotation); RotationalTransform.rotation = Quaternion.Slerp(lastVisualRot, visualRot, 1f / Time.fixedDeltaTime); } }
public short[,] Scan(int scanLayers) { int widthPeriods = Size.x.Div(Interval).CeilToInt(); int heightPeriods = Size.y.Div(Interval).CeilToInt(); short[,] heightMap = new short[widthPeriods, heightPeriods]; Vector3 startPos = _bottomLeft.ToVector3(HeightBounds.y.ToFloat()); Vector3 scanPos = startPos; float dist = (HeightBounds.y - HeightBounds.x).ToFloat(); float fRes = Interval.ToFloat(); for (int x = 0; x < widthPeriods; x++) { scanPos.z = startPos.z; for (int y = 0; y < heightPeriods; y++) { RaycastHit hit; long height; if (Physics.Raycast(scanPos, Vector3.down, out hit, dist, scanLayers, QueryTriggerInteraction.UseGlobal)) { height = FixedMath.Create(hit.point.y); } else { height = HeightBounds.x; } heightMap[x, y] = Compress(height); scanPos.z += fRes; } scanPos.x += fRes; } return(heightMap); }
public void Initialize(Vector3d StartPosition, Vector2d StartRotation, bool isDynamic = true) { Active = true; PositionalTransform = _positionalTransform; RotationalTransform = _rotationalTransform; if (!Setted) { this.Setup(null); } this.RaycastVersion = 0; this.HeightPosChanged = true; CheckVariables(); PositionChanged = true; RotationChanged = true; VelocityChanged = true; PositionChangedBuffer = true; RotationChangedBuffer = true; Priority = BasePriority; Velocity = Vector2d.zero; VelocityMagnitude = 0; LastPosition = _position = StartPosition.ToVector2d(); _heightPos = StartPosition.z; _rotation = StartRotation; ForwardNeedsSet = true; FastRadius = this.Radius * this.Radius; XMin = 0; XMax = 0; YMin = 0; YMax = 0; PastGridXMin = int.MaxValue; PastGridXMax = int.MaxValue; PastGridYMin = int.MaxValue; PastGridYMax = int.MaxValue; if (Shape != ColliderType.None) { BuildPoints(); BuildBounds(); } ID = PhysicsManager.Assimilate(this, isDynamic); Partition.PartitionObject(this); if (PositionalTransform != null) { CanSetVisualPosition = true; _visualPosition = _position.ToVector3(HeightPos.ToFloat()); lastVisualPos = _visualPosition; PositionalTransform.position = _visualPosition; } else { CanSetVisualPosition = false; } if (RotationalTransform != null) { CanSetVisualRotation = true; visualRot = GetVisualRot(); // _rotationOffset = transform.GetComponent<InvasionDay.GeoHandler>()._eulerOffset; lastVisualRot = visualRot; } else { CanSetVisualRotation = false; } SetVisuals(); velocityPosition = Vector3.zero; this.ImmovableCollisionDirection = Vector2d.zero; PartitionChanged = true; }
public void Initialize(Vector2dHeight StartPosition, Vector2d StartRotation) { PositionalTransform = _positionalTransform; RotationalTransform = _rotationalTransform; if (!Setted) { this.Setup(null); } this.RaycastVersion = 0; this.HeightPosChanged = true; CheckVariables(); PositionChanged = true; RotationChanged = true; VelocityChanged = true; PositionChangedBuffer = true; RotationChangedBuffer = true; Priority = _basePriority; Velocity = Vector2d.zero; VelocityFastMagnitude = 0; LastPosition = _position = StartPosition.ToVector2d(); _heightPos = StartPosition.Height; _rotation = StartRotation; ForwardNeedsSet = true; XMin = 0; XMax = 0; YMin = 0; YMax = 0; PastGridXMin = int.MaxValue; PastGridXMax = int.MaxValue; PastGridYMin = int.MaxValue; PastGridYMax = int.MaxValue; if (Shape != ColliderType.None) { BuildPoints(); BuildBounds(); } ID = PhysicsManager.Assimilate(this); Partition.PartitionObject(this); if (PositionalTransform != null) { CanSetVisualPosition = true; _visualPosition = _position.ToVector3(HeightPos.ToFloat()); lastVisualPos = _visualPosition; PositionalTransform.position = _visualPosition; } else { CanSetVisualPosition = false; } if (RotationalTransform != null) { CanSetVisualRotation = true; visualRot = Quaternion.LookRotation(Forward.ToVector3(0f)); lastVisualRot = visualRot; RotationalTransform.rotation = visualRot; } else { CanSetVisualRotation = false; } }
private void DoSetVisualRotation(Vector2d rot) { lastVisualRot = visualRot; visualRot = Quaternion.LookRotation(rot.ToVector3(0f)); SetRotationBuffer = true; }
private void SetVisuals() { const bool test = false; if (HasParent) { } else { if (SetVisualPosition == false) { if (visualPositionReached == false) { visualPositionReached = !(SetVisualPosition = _positionalTransform.position != visualPosition); } } if (SetVisualRotation == false) { if (visualRotationReached == false) { visualRotationReached = !(SetVisualRotation = _rotationalTransform.rotation != this.visualRot); } } } if (test || this.SetVisualPosition) { if (HasParent) { this._positionalTransform.localPosition = this.LocalPosition.rotatedLeft.ToVector3(visualPosition.y - _parent.visualPosition.y); } else { lastVisualPos = visualPosition; visualPosition.x = Position.x.ToFloat(); visualPosition.z = Position.y.ToFloat(); SetPositionBuffer = true; visualPositionReached = false; } } else if (HasParent == false) { if (SetPositionBuffer) { //_positionalTransform.position = visualPosition; SetPositionBuffer = false; } } if (test || this.SetVisualRotation) { if (HasParent) { this._rotationalTransform.localRotation = Quaternion.LookRotation(this.LocalRotation.rotatedLeft.ToVector3(0f)); } else { lastVisualRot = visualRot; visualRot = Quaternion.LookRotation(Rotation.ToVector3(0f)); SetRotationBuffer = true; visualRotationReached = false; } } else if (HasParent == false) { if (SetRotationBuffer) { //_rotationalTransform.rotation = visualRot; SetRotationBuffer = false; } } }