void Update() { AddPitchYaw(ref lookat, transform.position - CamTarget.GetTarget()); if (player.GetComponent <Rigidbody>().velocity.magnitude > 1) { AddPitchYaw(ref target, -player.GetComponent <Rigidbody>().velocity); } // if(Input.GetMouseButton(0) && player.rigidbody.velocity.magnitude > 1) // { // velocityAngle += Input.GetAxis("Mouse X") * sensitivityX; // // float spinVelocityDampen = 1-(angle * angle * SPIN_VELOSITY_DAMPEN_RATE * Time.deltaTime); // // // Vector3 TargetVel = Quaternion.Euler(0, angle, 0) * // player.rigidbody.velocity * // Mathf.Clamp01(spinVelocityDampen); // // player.transform.LookAt(TargetVel); // // // player.rigidbody.velocity = Vector3.Lerp(player.rigidbody.velocity, TargetVel,0) // camInterp2 += mouse; // // // in we spin 365 this makes it so it only spinns back 5 // shrinkAngle(ref camInterp2); // // // camInterp1 = camInterp2; // } //else // camInterp1 interpolates towards 0 and camInterp2 interpolates towards camInterp1 // provided they both start at the same place this gives camInterp2 a smooth acceleration and // deceleration // camInterp1 = Vector2.Lerp(camInterp1, Vector2.zero, CAM_RETURN_RATE * Time.deltaTime); // camInterp2 = Vector2.Lerp(camInterp2, camInterp1, CAM_RETURN_RATE * Time.deltaTime); Vector3 toLookatPos = transform.position - CamTarget.GetTarget(); AddPitchYaw(ref lookat, toLookatPos); Vector2 midpointGase = Vector2.Lerp(target, lookat, CamTarget.sWeight); worldInterp = Vector2.Lerp(worldInterp, midpointGase, CamTarget.sRate * Time.deltaTime); transform.localEulerAngles = worldInterp; // + camInterp2; //shrinkAngle(ref target); transform.position = player.transform.position; }
public CamPath(int loop, TimeSpan duration, string mode, string interpolation, CamTarget target, List <CamNode> points, double cameraFollowSpeed) { _loop = loop; _duration = duration; _mode = mode; _interpolation = interpolation; Target = target; Nodes = points; CameraFollowSpeed = cameraFollowSpeed; }
// Get the desired rotation. Quaternion CalculateDesiredRotation() { // The look at position quaternion Quaternion lookAtRot = Quaternion.LookRotation(CamTarget.GetTarget() - target.transform.position); // The rotation of the player. Quaternion forwardRot = Quaternion.LookRotation(target.transform.forward); // Use the variables in the trigger area to calculate the // desired rotation. Quaternion rot = Quaternion.Lerp(forwardRot, lookAtRot, CamTarget.sWeight); return(rot); }
public void Detach() { if (rope.enabled) { CamTarget.UnGrappled(); } rope.enabled = false; foreach (GrappleData grappleData in grapples) { Destroy(grappleData.gameObject); } grapples.Clear(); UnsetGrapple(); }
static void MenuDumpModels() { GameObject go = Selection.activeGameObject; go.AddComponent <Outfitter>(); go.AddComponent <CharacterDemoController>(); Transform[] tms = go.transform.GetComponentsInChildren <Transform>(); foreach (Transform tm in tms) { if (tm.gameObject.GetComponent <Renderer>() != null) { tm.gameObject.GetComponent <Renderer>().enabled = false; } } Outfitter o = go.transform.GetComponent <Outfitter>(); o.weapons = new List <WeaponSlot>(); WeaponSlot weap = new WeaponSlot(); for (int i = 0; i < 9; i++) { weap = new WeaponSlot(); o.weapons.Add(weap); o.weapons[i].models = new List <Renderer>(); } foreach (Transform tm in tms) { if (tm.gameObject.name.ToLower() == "gladius02") { o.weapons[1].models.Add(tm.gameObject.GetComponent <Renderer>()); } if (tm.gameObject.name.ToLower() == "longsword") { o.weapons[2].models.Add(tm.gameObject.GetComponent <Renderer>()); } if (tm.gameObject.name.ToLower() == "bow") { o.weapons[3].models.Add(tm.gameObject.GetComponent <Renderer>()); } if (tm.gameObject.name.ToLower() == "gladius02") { o.weapons[4].models.Add(tm.gameObject.GetComponent <Renderer>()); } if (tm.gameObject.name.Contains("Pistol")) { o.weapons[5].models.Add(tm.gameObject.GetComponent <Renderer>()); } if (tm.gameObject.name.Contains("SpaceRifle")) { o.weapons[6].models.Add(tm.gameObject.GetComponent <Renderer>()); } if (tm.gameObject.name.ToLower() == "spear") { o.weapons[7].models.Add(tm.gameObject.GetComponent <Renderer>()); } if (tm.gameObject.name.ToLower() == "broadsword") { o.weapons[8].models.Add(tm.gameObject.GetComponent <Renderer>()); } } foreach (Transform tm in tms) { if (tm.gameObject.name.ToLower() == "gladius") { o.weapons[4].models.Add(tm.gameObject.GetComponent <Renderer>()); } if (tm.gameObject.name.ToLower() == "arrow") { o.weapons[3].models.Add(tm.gameObject.GetComponent <Renderer>()); } if (tm.gameObject.name.ToLower() == "shield01") { o.weapons[8].models.Add(tm.gameObject.GetComponent <Renderer>()); } } CharacterDemoController cdc = go.transform.GetComponent <CharacterDemoController>(); // cdc.floorPlane = GameObject.Find("Plane"); GameObject goct = GameObject.Find("CameraTarget"); CamTarget ct = goct.GetComponent <CamTarget>(); ct.target = go.transform; }
public void Initialise(List <CamNode> points, int loops, CamTarget target) { }
public void Initialise(List <CamNode> points, int loops, CamTarget target) { if (points.Count == 1) { throw new CamStudioException("At least two points are required"); } var iterations = loops == 0 ? 1 : loops == 1 ? 2 : 3; _sizeOfIteration = 1D / iterations; var size = points.Count * iterations; if (iterations > 1) { size++; } var xPoints = new double[size]; var yPoints = new double[size]; var zPoints = new double[size]; var yawPoints = new double[size]; var pitchPoints = new double[size]; var rollPoints = new double[size]; var fovPoints = new double[size]; var saturationPoints = new double[size]; var sepiaPoints = new double[size]; for (var j = 0; j < iterations; j++) { for (var i = 0; i < points.Count; i++) { xPoints[i + j * points.Count] = points[i].X; yPoints[i + j * points.Count] = points[i].Y; zPoints[i + j * points.Count] = points[i].Z; yawPoints[i + j * points.Count] = points[i].Yaw; pitchPoints[i + j * points.Count] = points[i].Pitch; rollPoints[i + j * points.Count] = points[i].Roll; fovPoints[i + j * points.Count] = points[i].FieldOfView; saturationPoints[i + j * points.Count] = points[i].Saturation; sepiaPoints[i + j * points.Count] = points[i].Sepia; } } if (iterations > 1) { xPoints[points.Count * iterations] = points[0].X; yPoints[points.Count * iterations] = points[0].Y; zPoints[points.Count * iterations] = points[0].Z; yawPoints[points.Count * iterations] = points[0].Yaw; pitchPoints[points.Count * iterations] = points[0].Pitch; rollPoints[points.Count * iterations] = points[0].Roll; fovPoints[points.Count * iterations] = points[0].FieldOfView; saturationPoints[points.Count * iterations] = points[0].Saturation; sepiaPoints[points.Count * iterations] = points[0].Sepia; } _xSpline = new CubicCatmullInterpolation(xPoints); _ySpline = new CubicCatmullInterpolation(yPoints); _zSpline = new CubicCatmullInterpolation(zPoints); _yawSpline = new CubicCatmullInterpolation(yawPoints); _pitchSpline = new CubicCatmullInterpolation(pitchPoints); _rollSpline = new CubicCatmullInterpolation(rollPoints); _fovSpline = new CubicCatmullInterpolation(fovPoints); _saturationSpline = new CubicCatmullInterpolation(saturationPoints); _sepiaSpline = new CubicCatmullInterpolation(sepiaPoints); }
internal new void Initialise(List <CamNode> points, int loops, CamTarget target) { if (target == null) { throw new Exception("No target found"); } var center = target.GetPosition(); if (center != null) { points.Add(points[0]); _target = target; var firstPoint = new Vec3d(points[0].X, points[0].Y, points[0].Z); var centerPoint = new Vec3d(center.X, center.Y, center.Z); _sphereOrigin = new Vec3d(firstPoint.X, firstPoint.Y, firstPoint.Z); _sphereOrigin.Sub(centerPoint); _radius = _sphereOrigin.Length(); var vecs = new List <double>(); var times = new List <double> { 0.0 }; vecs.Add(firstPoint.Y); var newPointsSorted = new List <CamNode> { points[0] }; for (var i = 1; i < points.Count - 1; i++) { var point = new Vec3d(points[i].X, firstPoint.Y, points[i].Z); point.Sub(centerPoint); var dot = point.Dot(_sphereOrigin); var det = ((point.X * _sphereOrigin.Z) - (point.Z * _sphereOrigin.X)); var angle = Math.Atan2(det, dot) * GameMath.RAD2DEG; if (angle < 0) { angle += 360; } var time = angle / 360; for (var j = 0; j < times.Count; j++) { if (times[j] > time) { times.Add(time); vecs.Add(points[i].Y); newPointsSorted.Add(points[i]); break; } } newPointsSorted.Add(points[i]); times.Add(time); vecs.Add(points[i].Y); } if (loops == 0) { newPointsSorted.Add(newPointsSorted[0].Clone()); } times.Add(1D); vecs.Add(firstPoint.Y); _yAxis = new HermiteInterpolation(times.ToArray(), vecs.ToArray()); base.Initialise(times.ToArray(), newPointsSorted, loops, target); } else { throw new Exception("Invalid target"); } }
public void Attach(RaycastHit hit, float distance, bool initialGrapple) { if (hit.collider != null && hit.collider.tag == "GrappleTarget") { if (rope.enabled) { return; } else { distance = (hit.collider.gameObject.GetComponent <GrappleGuide>().GrappleTo() - transform.position).magnitude; } } else { distance = (hit.point - transform.position).magnitude; } // Update grapple data list GrappleData grappleData = new GrappleData(); grappleData.gameObject = new GameObject("Grapple Placeholder"); if (hit.collider != null && hit.collider.tag == "GrappleTarget") { Transform t = hit.collider.gameObject.GetComponent <GrappleGuide>().grappleTo; if (initialGrapple) { CamTarget.Grappled(t); } grappleData.gameObject.transform.position = t.position; } else { if (initialGrapple) { if (hit.collider != null) { CamTarget.Grappled(hit.collider.transform); } else { CamTarget.Grappled(transform); } } grappleData.gameObject.transform.position = hit.point; } grappleData.maxDistance = distance; if (hit.collider != null) { grappleData.gameObject.transform.parent = (grappleFollowMoving ? hit.collider.gameObject.transform : null); } // Offset position a little so the rope is visible // grappleData.gameObject.transform.position += hit.normal * GrappleExtrusion; if (grapples.Count == 0) { grappleData.gameObject.transform.rotation = Quaternion.LookRotation(hit.normal) * Quaternion.Euler(90, 0, 0); } else { grappleData.gameObject.transform.LookAt(grapples[grapples.Count - 1].gameObject.transform, -GetComponent <Rigidbody>().velocity); grappleData.offset = hit.normal * GrappleExtrusion; } // Add grapple data to collection grapples.Add(grappleData); // Update grapple SetGrapple(grappleData); }
protected void Initialise(double[] times, List <CamNode> points, int loops, CamTarget target) { if (points.Count == 1) { throw new CamStudioException("At least two points are required"); } var iterations = loops == 0 ? 1 : loops == 1 ? 2 : 3; _sizeOfIteration = 1D / iterations; var size = points.Count * iterations; if (iterations > 1) { size++; } var xPoints = new double[size]; var yPoints = new double[size]; var zPoints = new double[size]; var yawPoints = new double[size]; var pitchPoints = new double[size]; var rollPoints = new double[size]; var fovPoints = new double[size]; var saturationPoints = new double[size]; var sepiaPoints = new double[size]; var newTimes = new double[size]; for (var j = 0; j < iterations; j++) { if (times != null) { for (var i = 0; i < times.Length; i++) { var index = i + points.Count * j; if (index < size) { newTimes[index] = times[i] * _sizeOfIteration + _sizeOfIteration * j; } } } for (var i = 0; i < points.Count; i++) { xPoints[i + j * points.Count] = points[i].X; yPoints[i + j * points.Count] = points[i].Y; zPoints[i + j * points.Count] = points[i].Z; yawPoints[i + j * points.Count] = points[i].Yaw; pitchPoints[i + j * points.Count] = points[i].Pitch; rollPoints[i + j * points.Count] = points[i].Roll; fovPoints[i + j * points.Count] = points[i].FieldOfView; saturationPoints[i + j * points.Count] = points[i].Saturation; sepiaPoints[i + j * points.Count] = points[i].Sepia; } if (iterations > 1) { xPoints[points.Count * iterations] = points[0].X; yPoints[points.Count * iterations] = points[0].Y; zPoints[points.Count * iterations] = points[0].Z; yawPoints[points.Count * iterations] = points[0].Yaw; pitchPoints[points.Count * iterations] = points[0].Pitch; rollPoints[points.Count * iterations] = points[0].Roll; fovPoints[points.Count * iterations] = points[0].FieldOfView; saturationPoints[points.Count * iterations] = points[0].Saturation; sepiaPoints[points.Count * iterations] = points[0].Sepia; } _xSpline = new HermiteInterpolation(HermiteTension.Normal, xPoints); _ySpline = new HermiteInterpolation(HermiteTension.Normal, yPoints); _zSpline = new HermiteInterpolation(HermiteTension.Normal, zPoints); if (times == null) { _yawSpline = new HermiteInterpolation(yawPoints); _pitchSpline = new HermiteInterpolation(pitchPoints); _rollSpline = new HermiteInterpolation(rollPoints); _fovSpline = new HermiteInterpolation(fovPoints); _saturationSpline = new HermiteInterpolation(saturationPoints); _sepiaSpline = new HermiteInterpolation(sepiaPoints); } else { _yawSpline = new HermiteInterpolation(newTimes, yawPoints); _pitchSpline = new HermiteInterpolation(newTimes, pitchPoints); _rollSpline = new HermiteInterpolation(newTimes, rollPoints); _fovSpline = new HermiteInterpolation(newTimes, fovPoints); _saturationSpline = new HermiteInterpolation(newTimes, saturationPoints); _sepiaSpline = new HermiteInterpolation(newTimes, sepiaPoints); } } }
public void Initialise(List <CamNode> points, int loops, CamTarget target) { Initialise(null, points, loops, target); }