public void CopyVertexPathData(VertexPath vertexPath, bool useLocalTransform) { space = vertexPath.space; isClosedLoop = vertexPath.isClosedLoop; localPoints = CopyArray(vertexPath.localPoints); localTangents = CopyArray(vertexPath.localTangents); localNormals = CopyArray(vertexPath.localNormals); times = CopyArray(vertexPath.times); length = vertexPath.length; cumulativeLengthAtEachVertex = CopyArray(vertexPath.cumulativeLengthAtEachVertex); bounds = vertexPath.bounds; up = vertexPath.up; if (useLocalTransform) { transformPosition = vertexPath.LinkedTransform.localPosition; transformRotation = vertexPath.LinkedTransform.localRotation; transformLossyScale = vertexPath.LinkedTransform.localScale; } else { transformPosition = vertexPath.LinkedTransform.position; transformRotation = vertexPath.LinkedTransform.rotation; transformLossyScale = vertexPath.LinkedTransform.lossyScale; } pathUpdated?.Invoke(); }
// Get the current vertex path public VertexPath GetVertexPath(Transform transform) { // create new vertex path if path was modified since this vertex path was created if (!vertexPathUpToDate || _vertexPath == null) { vertexPathUpToDate = true; _vertexPath = new VertexPath(bezierPath, transform, vertexPathMaxAngleError, vertexPathMinVertexSpacing); } return(_vertexPath); }
void Generate() { if (pathCreator != null && prefab != null && holder != null) { DestroyObjects(); VertexPath path = pathCreator.path; spacing = Mathf.Max(minSpacing, spacing); float dst = 0; while (dst < path.length) { Vector3 point = path.GetPointAtDistance(dst); Quaternion rot = path.GetRotationAtDistance(dst); Instantiate(prefab, point, rot, holder.transform); dst += spacing; } } }
void RunInput() { float Mod = 1; if (_Ball) { Mod = 1.5f; } Vector3 GV = GroundVelocity; if (_RawInput == Vector3.zero) { if (_Grounded) { float Mag = GV.magnitude; Mag = Mathf.Clamp(Mag - (Decel * Time.fixedDeltaTime), 0, MaximumSpeed); if (Mag < 0.05) { Mag = 0; } GV = GV.normalized * Mag; } else { float Mag = GV.magnitude; Mag = Mathf.Clamp(Mag - (Decel * Time.fixedDeltaTime), 0, MaximumSpeed); if (Mag < 0.05) { Mag = 0; } GV = GV.normalized * Mag; } } else { Vector3 Input = _RawInput; if (_Grounded) { Vector3 Forward = Vector3.Cross(_GroundNormal, -Vector3.Cross(_CameraTransformDuplicate.Up, _CameraTransformDuplicate.Forward)) * _RawInput.z; Vector3 Right = Vector3.Cross(_GroundNormal, _CameraTransformDuplicate.Forward) * _RawInput.x; //Input = Quaternion.FromToRotation(Vector3.forward, Vector3.Cross(_GroundNormal, -Vector3.Cross(_CameraTransformDuplicate.Up, _CameraTransformDuplicate.Forward))) * Input; //Input = (Vector3.Cross(_GroundNormal, -Vector3.Cross(_CameraTransformDuplicate.Up, _CameraTransformDuplicate.Forward)) * _RawInput.z) + (Vector3.Cross(_CameraTransformDuplicate.Up, _CameraTransformDuplicate.Forward) * _RawInput.x); Input = Forward + Right; //Debug.Log(Input); if (GV.magnitude < ControlSpeed) { float Mag = GV.magnitude; GV = GV + (Input.normalized * Acell * Time.fixedDeltaTime * Mod); if (GV.magnitude > ControlSpeed) { GV = GV.normalized * ControlSpeed; } Mag = Mathf.Clamp(GV.magnitude, Mag, MaximumSpeed); GV = Turn(GV, Input, TurningSpeed, Mag); } else { float Mag = GV.magnitude; GV = Turn(GV, Input, TurningSpeed, Mag); } if (GV.magnitude > MaximumSpeed) { GV = GV.normalized * MaximumSpeed; } } else { Input = (Vector3.Cross(_GroundNormal, -Vector3.Cross(_CameraTransformDuplicate.Up, _CameraTransformDuplicate.Forward)) * _RawInput.z) + (Vector3.Cross(_CameraTransformDuplicate.Up, _CameraTransformDuplicate.Forward) * _RawInput.x); if (GV.magnitude < ControlSpeed) { float Mag = GV.magnitude; GV = GV + (Input.normalized * AirAcell * Time.fixedDeltaTime * Mod); if (GV.magnitude > ControlSpeed) { GV = GV.normalized * ControlSpeed; } Mag = Mathf.Clamp(GV.magnitude, Mag, MaximumSpeed); GV = Turn(GV, Input, AirTurningSpeed, Mag); } else { float Mag = GV.magnitude; GV = Turn(GV, Input, AirTurningSpeed, Mag); //Vector3.Lerp(GV.normalized, Input.normalized, Time.fixedDeltaTime * AirTurningSpeed).normalized * Mag; } if (GV.magnitude > MaximumSpeed) { GV = GV.normalized * MaximumSpeed; } } } if (_2DZone) { PathCreation.VertexPath _Path = _2DZone.GetActivePath(); Vector3 _LocalPositionPath = transform.InverseTransformPoint(_Path.GetClosestPointOnPath(transform.position)); Vector3 _LocalPosition = new Vector3(_LocalPositionPath.x, transform.InverseTransformPoint(transform.position).y, _LocalPositionPath.z); Vector3 _PositionPath = _Path.GetClosestPointOnPath(transform.position); Vector3 RelativePos = transform.position - _PositionPath; Vector3 Normal = _Path.GetNormalAtDistance(_Path.GetClosestDistanceAlongPath(transform.position) + 1); transform.position = Vector3.Lerp(transform.position, _PositionPath + Vector3.ProjectOnPlane(RelativePos, Normal), Time.fixedDeltaTime * 5); GV = Vector3.ProjectOnPlane(GV, Normal); } GroundVelocity = GV; }
public void SetPath(PathCreation.VertexPath newPath, PathCreation.EndOfPathInstruction eopi) { myPath = newPath; myEndOfPathInstruction = eopi; }
// Another cursed method by Charles. I'm sorry mom. public VertexPath GetVertexPathNow(Transform transform) { _vertexPath = new VertexPath(bezierPath, transform, vertexPathMaxAngleError, vertexPathMinVertexSpacing); return(_vertexPath); }
public void Update() { myVertPath = editorData.GetVertexPathNow(gameObject.transform); trackLength = myVertPath.length; }