public override void OnEnable() { base.OnEnable(); UserPreferences.singleton.headCollider.gameObject.SetActive(false); if (SuperController.singleton.MonitorCenterCamera != null) { var monitorCenterCameraTransform = SuperController.singleton.MonitorCenterCamera.transform; monitorCenterCameraTransform.localEulerAngles = Vector3.zero; } _headControlSnapshot = FreeControllerV3Snapshot.Snap(_headControl); _headControl.canGrabPosition = false; _headControl.canGrabRotation = false; _previousInterpolation = _headControlRB.interpolation; if (!allowPersonHeadRotationJSON.val) { _headControlRB.interpolation = RigidbodyInterpolation.Interpolate; } if (rotationLockJSON.val) { GlobalSceneOptions.singleton.disableNavigation = true; } StartCoroutine(OnEnableCo()); }
public RigidBodyInfo(Rigidbody source) { this.isKinematic = source.isKinematic; this.useGravity = source.useGravity; this.freezeRotation = source.freezeRotation; this.detectCollisions = source.detectCollisions; this.useConeFriction = source.useConeFriction; this.velocity = source.velocity; this.position = source.position; this.rotation = source.rotation; this.angularVelocity = source.angularVelocity; this.centerOfMass = source.centerOfMass; this.inertiaTensor = source.inertiaTensor; this.inertiaTensorRotation = source.inertiaTensorRotation; this.drag = source.drag; this.angularDrag = source.angularDrag; this.mass = source.mass; this.sleepVelocity = source.sleepVelocity; this.sleepAngularVelocity = source.sleepAngularVelocity; this.maxAngularVelocity = source.maxAngularVelocity; this.constraints = source.constraints; this.collisionDetectionMode = source.collisionDetectionMode; this.interpolation = source.interpolation; this.solverIterationCount = source.solverIterationCount; }
public void SetTarget ( Transform newTarget , bool snap ) { // If there was a target, reset its interpolation value if it had a rigidbody. if (target) { // Reset the old target's interpolation back to the saved value. Rigidbody targetRigidbody = target.GetComponent<Rigidbody>(); if (targetRigidbody) targetRigidbody.interpolation = savedInterpolationSetting; } // Set our current target to be the value passed to SetTarget () target = newTarget; // Now, save the new target's interpolation setting and set it to interpolate for now. // This will make our camera move more smoothly. Only do this if we didn't set the // target to null (nothing). if (target) { Rigidbody targetRigidbody = target.GetComponent<Rigidbody> (); if (targetRigidbody) { savedInterpolationSetting = targetRigidbody.interpolation; targetRigidbody.interpolation = RigidbodyInterpolation.Interpolate; } } // If we should snap the camera to the target, do so now. // Otherwise, the camera's position will change in the LateUpdate () function. if (snap) { transform.position = GetGoalPosition (); } }
private void LiftPickup(Collider other) { //get where to move item once its picked up Mesh otherMesh = other.GetComponent <MeshFilter>().mesh; holdPos = transform.position; holdPos.y += (GetComponent <Collider>().bounds.extents.y) + (otherMesh.bounds.extents.y) + gap; //if there is space above our head, pick up item (layermask index 2: "Ignore Raycast", anything on this layer will be ignored) if (!Physics.CheckSphere(holdPos, checkRadius, 2)) { gizmoColor = Color.green; heldObj = other.gameObject; objectDefInterpolation = heldObj.GetComponent <Rigidbody>().interpolation; heldObj.GetComponent <Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate; heldObj.transform.position = holdPos; heldObj.transform.rotation = transform.rotation; AddJoint(); //here we adjust the mass of the object, so it can seem heavy, but not effect player movement whilst were holding it heldObj.GetComponent <Rigidbody>().mass *= weightChange; //make sure we don't immediately throw object after picking it up timeOfPickup = Time.time; } //if not print to console (look in scene view for sphere gizmo to see whats stopping the pickup) else { gizmoColor = Color.red; print("Can't lift object here. If nothing is above the player, make sure triggers are set to layer index 2 (ignore raycast by default)"); } }
public void OnGUI() { // Instead of 'awake' we use Initialization checks InitStyles(); GUILayout.Label("* Select the Hierarchy Root", EditorStyles.whiteMiniLabel); FilterFields(); ProcessButton(); GUILayout.Space(5); EditorGUIUtility.LookLikeControls(0f, 0f); Mass = EditorGUILayout.FloatField("Mass", Mass); Drag = EditorGUILayout.FloatField("Drag", Drag); AngularDrag = EditorGUILayout.FloatField("Angular Drag", AngularDrag); UseGravity = GUILayout.Toggle(UseGravity, "Use Gravity"); IsKinematic = GUILayout.Toggle(IsKinematic, "Is Kinematic"); Interpolate = (RigidbodyInterpolation)EditorGUILayout.EnumPopup("Interpolate", Interpolate); CollisionDetectionMode = (CollisionDetectionMode)EditorGUILayout.EnumPopup("Collision Detection", CollisionDetectionMode); Constraints = EditorGUILayout.Foldout(Constraints, "Constraints"); if (Constraints) { ConstraintFields(); } }
protected override void ReadFromImpl(object obj) { base.ReadFromImpl(obj); Rigidbody uo = (Rigidbody)obj; velocity = uo.velocity; angularVelocity = uo.angularVelocity; drag = uo.drag; angularDrag = uo.angularDrag; mass = uo.mass; useGravity = uo.useGravity; maxDepenetrationVelocity = uo.maxDepenetrationVelocity; isKinematic = uo.isKinematic; freezeRotation = uo.freezeRotation; constraints = uo.constraints; collisionDetectionMode = uo.collisionDetectionMode; centerOfMass = uo.centerOfMass; detectCollisions = uo.detectCollisions; position = uo.position; rotation = uo.rotation; interpolation = uo.interpolation; solverIterations = uo.solverIterations; sleepThreshold = uo.sleepThreshold; maxAngularVelocity = uo.maxAngularVelocity; solverVelocityIterations = uo.solverVelocityIterations; }
public void SetTarget(Transform newTarget, bool snap) { if ((bool)target) { Rigidbody rigidbody = target.GetComponent("Rigidbody") as Rigidbody; if ((bool)rigidbody) { rigidbody.interpolation = savedInterpolationSetting; } } target = newTarget; if ((bool)target) { Rigidbody rigidbody2 = target.GetComponent("Rigidbody") as Rigidbody; if ((bool)rigidbody2) { savedInterpolationSetting = rigidbody2.interpolation; rigidbody2.interpolation = RigidbodyInterpolation.Interpolate; } } if (snap) { base.transform.position = GetGoalPosition(); } }
private void LiftPickup(Collider other) { //get where to move item once its picked up Mesh otherMesh = other.GetComponent <MeshFilter>().mesh; holdPos = transform.position + transform.forward * holdOffset.z + transform.right * holdOffset.x + transform.up * holdOffset.y; holdPos.y += (GetComponent <Collider>().bounds.extents.y) + (otherMesh.bounds.extents.y); //if there is space above our head, pick up item (this uses the defaul CheckSphere layers, you can add a layerMask parameter here if you need to though!) if (!Physics.CheckSphere(holdPos, checkRadius)) { gizmoColor = Color.green; heldObj = other.gameObject; objectDefInterpolation = heldObj.GetComponent <Rigidbody>().interpolation; heldObj.GetComponent <Rigidbody>().collisionDetectionMode = CollisionDetectionMode.Continuous; heldObj.GetComponent <Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate; heldObj.transform.position = holdPos; heldObj.transform.rotation = transform.rotation; heldObj.transform.Rotate(new Vector3(0, 0, 90)); AddJoint(); //here we adjust the mass of the object, so it can seem heavy, but not effect player movement whilst were holding it heldObj.GetComponent <Rigidbody>().mass *= weightChange; //make sure we don't immediately throw object after picking it up timeOfPickup = Time.time; } //if not print to console (look in scene view for sphere gizmo to see whats stopping the pickup) else { gizmoColor = Color.red; print("Can't lift object here. If nothing is above the player, perhaps you need to add a layerMask parameter to line 136 of the code in this script," + "the CheckSphere function, in order to make sure it isn't detecting something above the players head that is invisible"); } }
void ChangeRigidbodyToKinematic(bool isKinematic, RigidbodyInterpolation interpolation, CollisionDetectionMode collisionDetection) { //Camera may jitter without interpolation or if its changed back to None _characterRigidBody.interpolation = interpolation; _characterRigidBody.collisionDetectionMode = collisionDetection; _characterRigidBody.isKinematic = isKinematic; }
private void OnAttachedToHand(Hand hand) { hadInterpolation = this.rigidbody.interpolation; bracelet = hand.GetBracelet(); Signal sig = new Sine(100) * new Envelope(0.1, 0.1); bracelet.tactors.VibrateAll(sig); }
// Token: 0x060026F9 RID: 9977 RVA: 0x000B4708 File Offset: 0x000B2908 public static void RegisterCharacterMotor(KinematicCharacterMotor motor) { KinematicCharacterSystem.CharacterMotors.Add(motor); RigidbodyInterpolation interpolation = (KinematicCharacterSystem._internalInterpolationMethod == CharacterSystemInterpolationMethod.Unity) ? RigidbodyInterpolation.Interpolate : RigidbodyInterpolation.None; motor.Rigidbody.interpolation = interpolation; }
private void CopyRigidbodySettings() { Rigidbody oldRb = gameObject.GetComponent <Rigidbody>(); if (oldRb == null) { return; } t_velocity = oldRb.velocity; t_angularVelocity = oldRb.angularVelocity; t_drag = oldRb.drag; t_angularDrag = oldRb.angularDrag; t_mass = oldRb.mass; t_useGravity = oldRb.useGravity; t_isKinematic = oldRb.isKinematic; t_freezeRotation = oldRb.freezeRotation; t_constraints = oldRb.constraints; t_collisionDetectionMod = oldRb.collisionDetectionMode; t_centerOfMass = oldRb.centerOfMass; t_inertiaTensorRotation = oldRb.inertiaTensorRotation; t_inertiaTensor = oldRb.inertiaTensor; t_detectCollisions = oldRb.detectCollisions; t_useConeFriction = oldRb.useConeFriction; t_position = oldRb.position; t_rotation = oldRb.rotation; t_interpolation = oldRb.interpolation; //t_solverIterationCount = oldRb.solverIterations; t_sleepVelocity = oldRb.sleepVelocity; t_sleepAngularVelocity = oldRb.sleepAngularVelocity; t_maxAngularVelocity = oldRb.maxAngularVelocity; }
//------------------------------------------------- protected virtual void OnAttachedToHand(Hand hand) { //Debug.Log("Pickup: " + hand.GetGrabStarting().ToString()); hadInterpolation = this.rigidbody.interpolation; attached = true; onPickUp.Invoke(); hand.HoverLock(null); rigidbody.interpolation = RigidbodyInterpolation.None; velocityEstimator.BeginEstimatingVelocity(); attachTime = Time.time; attachPosition = transform.position; attachRotation = transform.rotation; if (attachEaseIn) { attachEaseInTransform = hand.objectAttachmentPoint; } snapAttachEaseInCompleted = false; }
public void SetInterpolation(RigidbodyInterpolation ri) { foreach (var r in _lstRigidbody) { r.interpolation = ri; } }
private void PickUp(Ray ray) { RaycastHit hit; Debug.DrawRay(ray.origin, ray.direction * maxGrabRange, Color.blue, 0.01f); if (Physics.Raycast(ray, out hit, maxGrabRange)) { // Don't pick up kinematic rigidbodies (they can't move) if (hit.rigidbody != null && hit.rigidbody.gameObject.tag == "moveable")//&& !hit.rigidbody.isKinematic) { initialInterpolationSetting = hit.rigidbody.interpolation; hit.rigidbody.gameObject.layer = 11; hit.rigidbody.interpolation = RigidbodyInterpolation.Interpolate; hit.rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; hit.rigidbody.useGravity = false; hit.rigidbody.freezeRotation = true; hit.rigidbody.isKinematic = true; rotationDifferenceEuler = hit.rigidbody.transform.rotation.eulerAngles - transform.rotation.eulerAngles; holdDistance = hit.distance; //hit.rigidbody.position = Vector3.Lerp(hit.transform.position, holdPosition, Time.deltaTime * 15); selected = hit.rigidbody; } } }
/** * Pick up a pickup-able object */ private void LiftPickup(Collider other) { Mesh otherMesh = other.GetComponent <MeshFilter> ().mesh; holdPos = transform.position; holdPos.y += (GetComponent <Collider> ().bounds.extents.y) + (otherMesh.bounds.extents.y) + gap; // Pick up obj if there's space above the head if (!Physics.CheckSphere(holdPos, checkRadius, 2)) { heldObj = other.gameObject; Rigidbody rb = heldObj.GetComponent <Rigidbody> (); objectDefInterpolation = rb.interpolation; // Store the picked up object's interpolation rb.interpolation = RigidbodyInterpolation.Interpolate; heldObj.transform.position = holdPos; heldObj.transform.rotation = transform.rotation; AddJoint(); // Adjust object mass rb.mass *= weightChange; pickupTime = Time.time; EventManager.Instance.Send(new PickedUpObjectEvent(heldObj)); } else { print("Can't lift object here. If nothing is above the player, make sure triggers are set to layer index 2 (ignore raycast by default)"); } }
public RigidbodyState(Rigidbody rb) { if (rb == null) { throw new System.Exception("State rigidbody is null"); } this.angularDrag = rb.angularDrag; this.angularVelocity = rb.angularVelocity; this.centerOfMass = rb.centerOfMass; this.collisionDetectionMode = rb.collisionDetectionMode; this.constraints = rb.constraints; this.detectCollisions = rb.detectCollisions; this.drag = rb.drag; this.freezeRotation = rb.freezeRotation; this.inertiaTensor = rb.inertiaTensor; this.inertiaTensorRotation = rb.inertiaTensorRotation; this.interpolation = rb.interpolation; this.isKinematic = rb.isKinematic; this.mass = rb.mass; this.maxAngularVelocity = rb.maxAngularVelocity; this.maxDepenetrationVelocity = rb.maxDepenetrationVelocity; this.position = rb.position; this.rotation = rb.rotation; this.sleepThreshold = rb.sleepThreshold; this.solverIterations = rb.solverIterations; this.solverVelocityIterations = rb.solverVelocityIterations; this.useGravity = rb.useGravity; this.velocity = rb.velocity; this.worldCenterOfMass = rb.worldCenterOfMass; }
// Token: 0x060026FC RID: 9980 RVA: 0x000B4770 File Offset: 0x000B2970 public static void RegisterPhysicsMover(PhysicsMover mover) { KinematicCharacterSystem.PhysicsMovers.Add(mover); RigidbodyInterpolation interpolation = (KinematicCharacterSystem._internalInterpolationMethod == CharacterSystemInterpolationMethod.Unity) ? RigidbodyInterpolation.Interpolate : RigidbodyInterpolation.None; mover.Rigidbody.interpolation = interpolation; }
public RigidBodyInfo(Rigidbody source) { isKinematic = source.isKinematic; useGravity = source.useGravity; freezeRotation = source.freezeRotation; detectCollisions = source.detectCollisions; useConeFriction = source.useConeFriction; velocity = source.velocity; position = source.position; rotation = source.rotation; angularVelocity = source.angularVelocity; centerOfMass = source.centerOfMass; inertiaTensor = source.inertiaTensor; inertiaTensorRotation = source.inertiaTensorRotation; drag = source.drag; angularDrag = source.angularDrag; mass = source.mass; sleepVelocity = source.sleepVelocity; sleepAngularVelocity = source.sleepAngularVelocity; maxAngularVelocity = source.maxAngularVelocity; constraints = source.constraints; collisionDetectionMode = source.collisionDetectionMode; interpolation = source.interpolation; solverIterationCount = source.solverIterationCount; }
public EquipInfo(Item sceneItem) { originallyActive = sceneItem.gameObject.activeSelf; originalParent = sceneItem.transform.parent; Rigidbody rb = sceneItem.rigidbody; if (rb != null) { attachedRigidbodyWasKinematic = rb.isKinematic; attachedRigidbodyUsedGravity = rb.useGravity; rbInterpolation = rb.interpolation; rb.interpolation = RigidbodyInterpolation.None; if (sceneItem.itemBehavior.equipType == EquipType.Normal) { collisionDetectionMode = rb.collisionDetectionMode; if (rb.collisionDetectionMode == CollisionDetectionMode.Continuous) { rb.collisionDetectionMode = CollisionDetectionMode.Discrete; } rb.isKinematic = true; } if (sceneItem.itemBehavior.equipType == EquipType.Physics) { rb.useGravity = false; } } if (!originallyActive) { sceneItem.gameObject.SetActive(true); } }
//------------------------------------------------- protected virtual void OnAttachedToHand(Hand hand) { //Debug.Log("<b>[SteamVR Interaction]</b> Pickup: " + hand.GetGrabStarting().ToString()); hadInterpolation = this.rigidbody.interpolation; attached = true; if (onPickUp != null) { onPickUp.Invoke(); } hand.HoverLock(null); rigidbody.interpolation = RigidbodyInterpolation.None; if (velocityEstimator != null) { velocityEstimator.BeginEstimatingVelocity(); } attachTime = Time.time; attachPosition = transform.position; attachRotation = transform.rotation; }
void Update() { if (!Input.GetMouseButton(0)) { // We are not holding the mouse button. Release the object and return before checking for a new one if (rigidbody != null) { // Reset the rigidbody to how it was before we grabbed it rigidbody.interpolation = initialInterpolationSetting; rigidbody = null; } return; } if (rigidbody == null) { // We are not holding an object, look for one to pick up Ray ray = CenterRay(); RaycastHit hit; Debug.DrawRay(ray.origin, ray.direction * maxGrabDistance, Color.blue, 0.01f); if (Physics.Raycast(ray, out hit, maxGrabDistance)) { // Don't pick up kinematic rigidbodies (they can't move) if (hit.rigidbody != null && !hit.rigidbody.isKinematic) { // Track rigidbody's initial information rigidbody = hit.rigidbody; initialInterpolationSetting = rigidbody.interpolation; rotationDifferenceEuler = hit.transform.rotation.eulerAngles - transform.rotation.eulerAngles; hitOffsetLocal = hit.transform.InverseTransformVector(hit.point - hit.transform.position); currentGrabDistance = Vector3.Distance(ray.origin, hit.point); // Set rigidbody's interpolation for proper collision detection when being moved by the player rigidbody.interpolation = RigidbodyInterpolation.Interpolate; } } } else { // We are already holding an object, listen for rotation input if (Input.GetKey(KeyCode.R)) { rotationInput += new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")); } } // NOTE: You may want to write some code here to prevent your player's aim from moving while you rotate objects // Eg. // playerAimScript.enabled = !Input.GetKey(KeyCode.R); }
static int IntToEnum(IntPtr L) { int arg0 = (int)LuaDLL.lua_tonumber(L, 1); RigidbodyInterpolation o = (RigidbodyInterpolation)arg0; LuaScriptMgr.PushEnum(L, o); return(1); }
public InteractiveObjectBoxLogicColliderDefinitionStruct(InteractiveObjectBoxLogicColliderDefinition InteractiveObjectBoxLogicColliderDefinition) { Enabled = InteractiveObjectBoxLogicColliderDefinition.Enabled; HasRigidBody = InteractiveObjectBoxLogicColliderDefinition.HasRigidBody; RigidbodyInterpolation = InteractiveObjectBoxLogicColliderDefinition.RigidbodyInterpolation; LocalCenter = InteractiveObjectBoxLogicColliderDefinition.LocalCenter; LocalSize = InteractiveObjectBoxLogicColliderDefinition.LocalSize; }
public RigidbodySettings(Rigidbody rb) { this.mass = rb.mass; this.useGravity = rb.useGravity; this.collisionDetectionMode = rb.collisionDetectionMode; this.interpolation = rb.interpolation; this.drag = rb.drag; this.angularDrag = rb.angularDrag; }
static void ApplyRigidBodyInterpolationModeOnServer(RigidbodyInterpolation interpolation) { VehicleManager.Instance.rigidbodyInterpolationOnServer = interpolation; if (NetUtils.IsServer) { foreach (var rb in Vehicle.AllVehicleRigidBodies) { rb.interpolation = interpolation; } } }
public void saveRigidbody(Rigidbody rb) { mass = rb.mass; drag = rb.drag; angularDrag = rb.angularDrag; useGravity = rb.useGravity; isKinematic = rb.isKinematic; interpolation = rb.interpolation; collisionDetection = rb.collisionDetectionMode; constraints = rb.constraints; }
static void ApplyRigidBodyInterpolationModeOnClient(RigidbodyInterpolation interpolation) { VehicleManager.Instance.rigidbodyInterpolationOnClient = interpolation; if (Net.NetStatus.IsClientOnly) { foreach (var rb in Vehicle.AllVehicleRigidBodies) { rb.interpolation = interpolation; } } }
public SCG_RigidBodySerialized(Rigidbody rigidbody) { mass = rigidbody.mass; drag = rigidbody.drag; angDrag = rigidbody.angularDrag; useGravity = rigidbody.useGravity; isKinematic = rigidbody.isKinematic; interpolate = rigidbody.interpolation; collDetect = rigidbody.collisionDetectionMode; constraints = rigidbody.constraints; }
public void SaveConfiguration(Rigidbody rigidbody) { this.mass = rigidbody.mass; this.drag = rigidbody.drag; this.angularDrag = rigidbody.angularDrag; this.useGravity = rigidbody.useGravity; this.isKinematic = rigidbody.isKinematic; this.interpolation = rigidbody.interpolation; this.collisionDetectionMode = rigidbody.collisionDetectionMode; this.contraints = rigidbody.constraints; }
private void GrabPushable(Collider other) { heldObj = other.gameObject; objectDefInterpolation = heldObj.GetComponent <Rigidbody>().interpolation; heldObj.GetComponent <Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate; AddJoint(); //no breakForce limit for pushables anymore because Unity 5's new physics system broke this. Perhaps it'll be fixed in future joint.breakForce = holdingBreakForce; joint.breakTorque = holdingBreakTorque; //stop player rotating in direction of movement, so they can face the block theyre pulling //playerMove.rotateSpeed = 0; }
/** * Pick up a pickup-able object */ private void LiftPickup(Collider other) { Mesh otherMesh = other.GetComponent<MeshFilter> ().mesh; holdPos = transform.position; holdPos.y += (GetComponent<Collider> ().bounds.extents.y) + (otherMesh.bounds.extents.y) + gap; // Pick up obj if there's space above the head if (!Physics.CheckSphere (holdPos, checkRadius, 2)) { heldObj = other.gameObject; Rigidbody rb = heldObj.GetComponent<Rigidbody> (); objectDefInterpolation = rb.interpolation; // Store the picked up object's interpolation rb.interpolation = RigidbodyInterpolation.Interpolate; heldObj.transform.position = holdPos; heldObj.transform.rotation = transform.rotation; AddJoint (); // Adjust object mass rb.mass *= weightChange; pickupTime = Time.time; EventManager.Instance.Send (new PickedUpObjectEvent (heldObj)); } else { print ("Can't lift object here. If nothing is above the player, make sure triggers are set to layer index 2 (ignore raycast by default)"); } }
private void CopyRigidbodySettings() { Rigidbody oldRb = gameObject.GetComponent<Rigidbody>(); if(oldRb == null) return; t_velocity = oldRb.velocity; t_angularVelocity = oldRb.angularVelocity; t_drag = oldRb.drag; t_angularDrag = oldRb.angularDrag; t_mass = oldRb.mass; t_useGravity = oldRb.useGravity; t_isKinematic = oldRb.isKinematic; t_freezeRotation = oldRb.freezeRotation; t_constraints = oldRb.constraints; t_collisionDetectionMod = oldRb.collisionDetectionMode; t_centerOfMass = oldRb.centerOfMass; t_inertiaTensorRotation = oldRb.inertiaTensorRotation; t_inertiaTensor = oldRb.inertiaTensor; t_detectCollisions = oldRb.detectCollisions; t_useConeFriction = oldRb.useConeFriction; t_position = oldRb.position; t_rotation = oldRb.rotation; t_interpolation = oldRb.interpolation; t_solverIterationCount = oldRb.solverIterationCount; #if UNITY_5 t_sleepThreshold = oldRb.sleepThreshold; #else t_sleepVelocity = oldRb.sleepVelocity; t_sleepAngularVelocity = oldRb.sleepAngularVelocity; #endif t_maxAngularVelocity = oldRb.maxAngularVelocity; }
private void LiftPickup(Collider other) { //get where to move item once its picked up Mesh otherMesh = other.GetComponent<MeshFilter>().mesh; holdPos = transform.position; holdPos.y += (GetComponent<Collider>().bounds.extents.y) + (otherMesh.bounds.extents.y) + gap; //if there is space above our head, pick up item (layermask index 2: "Ignore Raycast", anything on this layer will be ignored) if(!Physics.CheckSphere(holdPos, checkRadius, 2)) { //gizmoColor = Color.green; heldObj = other.gameObject; objectDefInterpolation = heldObj.GetComponent<Rigidbody>().interpolation; heldObj.GetComponent<Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate; heldObj.transform.position = holdPos; heldObj.transform.rotation = transform.rotation; AddJoint(); //here we adjust the mass of the object, so it can seem heavy, but not effect player movement whilst were holding it //heldObj.GetComponent<Rigidbody>().mass *= weightChange; //make sure we don't immediately throw object after picking it up timeOfPickup = Time.time; } //if not print to console (look in scene view for sphere gizmo to see whats stopping the pickup) else { //gizmoColor = Color.red; //print ("Can't lift object here. If nothing is above the player, make sure triggers are set to layer index 2 (ignore raycast by default)"); } }
/// <summary> /// Initializes a new instance of the <see cref="ZSStylusDragger.RigidbodyProperties"/> struct from a Rigidbody. /// </summary> public RigidbodyProperties(Rigidbody rb) { drag = rb.drag; angularDrag = rb.angularDrag; isKinematic = rb.isKinematic; useGravity = rb.useGravity; solverIterationCount = rb.solverIterationCount; interpolation = rb.interpolation; }
public void ResetRigidbodyVariables() { //reset rigidbody variables Mass=1f; Drag=0f; AngularDrag=0.05f; UseGravity=true; IsKinematic=false; Interpolation = RigidbodyInterpolation.None; CollisionDetection = CollisionDetectionMode.Discrete; FreezePositionX=false; FreezePositionY=false; FreezePositionZ=false; FreezeRotationX=false; FreezeRotationY=false; FreezeRotationZ=false; //apply changes SetRigidbodyVariables(); }
private static void AddRigidBodies(GameObject sGameObject, string gameObjectName, float rbMass, float rbDrag, float rbAngularDrag, bool rbUseGravity, bool rbIsKinematic, RigidbodyInterpolation rbInterpolation, CollisionDetectionMode rbCollisionDetectionMode) { if (sGameObject.name == gameObjectName) { var rigidBody = sGameObject.AddComponent<Rigidbody>(); rigidBody.isKinematic = rbIsKinematic; rigidBody.useGravity = rbUseGravity; rigidBody.mass = rbMass; rigidBody.drag = rbDrag; rigidBody.angularDrag = rbAngularDrag; rigidBody.interpolation = rbInterpolation; rigidBody.collisionDetectionMode = rbCollisionDetectionMode; } foreach (Transform childTransform in sGameObject.transform) { AddRigidBodies(childTransform.gameObject, gameObjectName, rbMass, rbDrag, rbAngularDrag, rbUseGravity, rbIsKinematic, rbInterpolation, rbCollisionDetectionMode); } }
public RigidbodySettings(Rigidbody rigidbody) { _rigidbody = rigidbody; _isKinematic = rigidbody.isKinematic; _velocity = rigidbody.velocity; _angularVelocity = rigidbody.angularVelocity; _mass = rigidbody.mass; _drag = rigidbody.drag; _angularDrag = rigidbody.angularDrag; _useGravity = rigidbody.useGravity; _interpolate = rigidbody.interpolation; _collisionDetection = rigidbody.collisionDetectionMode; _constraints = rigidbody.constraints; }
/** * Grab a pushable object */ private void GrabPushable(Collider other) { heldObj = other.gameObject; Rigidbody rb = heldObj.GetComponent<Rigidbody> (); objectDefInterpolation = rb.interpolation; // Store the picked up object's interpolation rb.interpolation = RigidbodyInterpolation.Interpolate; AddJoint (); joint.breakForce = pushBreakForce; joint.breakTorque = pushBreakTorque; // Stop player facing movement dir so that they face the grabbed obj playerController.rotateSpeed = 0; EventManager.Instance.Send (new PushObjectEvent (heldObj)); }
private void GrabPushable(Collider other) { heldObj = other.gameObject; objectDefInterpolation = heldObj.rigidbody.interpolation; heldObj.rigidbody.interpolation = RigidbodyInterpolation.Interpolate; AddJoint (); //set limits for when player will let go of object joint.breakForce = holdingBreakForce; joint.breakTorque = holdingBreakTorque; //stop player rotating in direction of movement, so they can face the block theyre pulling playerMove.rotateSpeed = 0; }
private void GrabPushable(Collider other) { heldObj = other.gameObject; objectDefInterpolation = heldObj.GetComponent<Rigidbody>().interpolation; heldObj.GetComponent<Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate; AddJoint (); //no breakForce limit for pushables anymore because Unity 5's new physics system broke this. Perhaps it'll be fixed in future joint.breakForce = Mathf.Infinity; joint.breakTorque = Mathf.Infinity; //stop player rotating in direction of movement, so they can face the block theyre pulling playerMove.rotateSpeed = 0; }
private void LiftPickup(Collider other) { //get where to move item once its picked up Mesh otherMesh = other.GetComponent<MeshFilter>().mesh; holdPos = transform.position + transform.forward * holdOffset.z + transform.right * holdOffset.x + transform.up * holdOffset.y; holdPos.y += (GetComponent<Collider>().bounds.extents.y) + (otherMesh.bounds.extents.y); //if there is space above our head, pick up item (this uses the defaul CheckSphere layers, you can add a layerMask parameter here if you need to though!) if(!Physics.CheckSphere(holdPos, checkRadius, mask)) { gizmoColor = Color.green; heldObj = other.gameObject; objectDefInterpolation = heldObj.GetComponent<Rigidbody>().interpolation; heldObj.GetComponent<Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate; heldObj.transform.position = holdPos; heldObj.transform.rotation = transform.rotation; heldObj.GetComponent<MoveOnPath>().held = true; AddJoint(); //here we adjust the mass of the object, so it can seem heavy, but not effect player movement whilst were holding it heldObj.GetComponent<Rigidbody>().mass *= weightChange; //make sure we don't immediately throw object after picking it up timeOfPickup = Time.time; } //if not print to console (look in scene view for sphere gizmo to see whats stopping the pickup) else { gizmoColor = Color.red; print ("Can't lift object here. If nothing is above the player, perhaps you need to add a layerMask parameter to line 136 of the code in this script," + "the CheckSphere function, in order to make sure it isn't detecting something above the players head that is invisible"); } }