public void cast() { if (castCounter == 0) { CountDownTimer.timer.Init(3.0f); } castCounter++; // timerObject.GetComponent<CountDownTimer>. Debug.Log("Trying to cast"); // Debug.Log("gauge Value was " + gaugeValue); if (rod.GetComponent<RodStatus>().getStatus() == "precasting") { rod.GetComponent<RodStatus>().setStatus("casting"); line.GetComponent<Renderer>().enabled = true; bobber.transform.position = rodEnd.transform.position; rb = bobber.GetComponent<Rigidbody>(); rb.velocity = Vector3.zero; if (orginalConstraint == null) orginalConstraint = rb.constraints; else rb.constraints = orginalConstraint; rodEnd.transform.DetachChildren(); bobber.GetComponent<Rigidbody>().useGravity = true; if(gaugeValue <= .20f){ gaugeValue = .20f; } rb.velocity = launchPoint.transform.forward * (gaugeValue * 60); } }
// Start is called before the first frame update void Start() { rb = this.GetComponent <Rigidbody>(); fightScript = GameObject.Find("arena1").transform.GetChild(0).transform.gameObject.GetComponent <FightManager>(); rbAttackConstraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezeRotationX; rbHitConstraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY; }
void Awake() { MyRB = GetComponent <Rigidbody>(); MyCollider = GetComponent <CapsuleCollider>(); GroundedConstraints = RigidbodyConstraints.FreezeRotation; }
void Start() { // Set components mRigidbody = rigidbody; constraints = mRigidbody.constraints; // Get users saved settings for ball sensitivity //ball_speed = PlayerPrefs.GetFloat("ball_speed", 9.0f); ball_speed = 20; ball_direction = 0; // Set gravity to physic settings gravity = Physics.gravity.y; // Set the type of controller used in game #if UNITY_EDITOR if (ApplicationData.ControllerType == ApplicationData.Controller.Tilt) controllerType = ApplicationData.Controller.Keyboard; else controllerType = ApplicationData.ControllerType; #endif // Get swipe input for ball movement Manager_Input.Swipe_Horizontal += HandleSwipe_Horizontal; }
//Start Function public void Start() { originalConstraints = this.gameObject.GetComponent <Rigidbody>().constraints; gm = GameManager.instance; //initialize gm to instance of game manager //set time_to_pay time_to_pay = gm.time_per_day; }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Debug.Log("Stop"); var rigidbody = animator.GetComponentInParent<Rigidbody>(); store = rigidbody.constraints; rigidbody.constraints = RigidbodyConstraints.FreezeAll; }
private void UpdateSkillLevel(PlayerSkill skill) { switch (skill.type) { case PlayerSkill.Type.JumpCount: m_currJumpIndex += skill.level; m_currJumpIndex = Mathf.Min(JUMP_COUNT.Length - 1, m_currJumpIndex); m_baseJumpCount = JUMP_COUNT[m_currJumpIndex]; m_jumpCount = m_baseJumpCount; break; case PlayerSkill.Type.Roll: m_currConstraintIndex += skill.level; m_currConstraintIndex = Mathf.Min(CONSTRAINTS.Length - 1, m_currConstraintIndex); m_baseConstraints = CONSTRAINTS[m_currConstraintIndex]; break; case PlayerSkill.Type.JumpDist: m_currJumpDistIndex += skill.level; m_currJumpDistIndex = Mathf.Min(JUMP_DIST_MODIFIER.Length - 1, m_currJumpDistIndex); m_jumpModifier = JUMP_DIST_MODIFIER[m_currJumpDistIndex]; break; case PlayerSkill.Type.Dash: m_currDashTimerIndex += skill.level; m_currDashTimerIndex = Mathf.Min(DASH_TIMER.Length - 1, m_currDashTimerIndex); m_baseDashTimer = DASH_TIMER[m_currDashTimerIndex]; m_dashCooldownTimer = m_baseDashTimer; break; } }
public void Stun() { if (stun != null) { return; } stun = StartCoroutine(StunCoroutine()); IEnumerator StunCoroutine() { IsStunned = true; RigidbodyConstraints normalConst = RB.constraints; RB.constraints = RigidbodyConstraints.FreezeAll; float doneTime = Time.time + stunTime; while (Time.time < doneTime) { Vector3 randomDir = new Vector3(Random.Range(-1, 1), 0, Random.Range(-1, 1)); Animator.SetFloat("Horizontal", randomDir.x); Animator.SetFloat("Vertical", randomDir.z); Animator.SetFloat("Magnitude", randomDir.magnitude); yield return(null); } IsStunned = false; RB.constraints = normalConst; yield return(new WaitForSeconds(immuneTime)); stun = null; } }
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; }
// Start is called before the first frame update protected override void Start() { base.Start(); m_baseJumpCount = JUMP_COUNT[m_currJumpIndex]; m_baseConstraints = CONSTRAINTS[m_currConstraintIndex]; m_jumpModifier = JUMP_DIST_MODIFIER[m_currJumpDistIndex]; m_baseDashTimer = DASH_TIMER[m_currDashTimerIndex]; m_rigidbody.constraints = m_baseConstraints; m_dashCooldownTimer = m_baseDashTimer; m_jumpCount = m_baseJumpCount; m_playerControls = GetComponent <PlayerController>().PlayerControls; m_eventManager = EventManager.Instance; if (m_cameraTransform == null) { m_cameraTransform = Camera.main.transform; } m_playerControls.Player.Dash.started += Dash; m_playerControls.Player.Jump.started += Jump; m_playerControls.Player.Horizontal.started += UpdateMovementHorizontal; m_playerControls.Player.Vertical.started += UpdateMovementVertical; m_playerControls.Player.Horizontal.canceled += UpdateMovementHorizontal; m_playerControls.Player.Vertical.canceled += UpdateMovementVertical; m_eventManager.AddSkillUnlockedListener(UpdateSkillLevel); }
private void Start() { originalConstraints = myBody.constraints; startPosition = transform.position; startRotation = transform.rotation; finishPoint = GameObject.FindGameObjectWithTag("FinishPoint").transform; }
void Start() { // Get components instance = this; coinCount = 0; coinText.GetComponent <Text> ().text = "" + coinCount; spRendMain = GameObject.Find("Player").transform.Find("SpriteMain").GetComponent <SpriteRenderer> (); spRend1 = GameObject.Find("Player").transform.Find("Sprite1").GetComponent <SpriteRenderer> (); spRend2 = GameObject.Find("Player").transform.Find("Sprite2").GetComponent <SpriteRenderer> (); spRend3 = GameObject.Find("Player").transform.Find("Sprite3").GetComponent <SpriteRenderer> (); trail1 = GameObject.Find("Player").transform.Find("Sprite1").GetComponent <TrailRenderer> (); trail2 = GameObject.Find("Player").transform.Find("Sprite2").GetComponent <TrailRenderer> (); trail3 = GameObject.Find("Player").transform.Find("Sprite3").GetComponent <TrailRenderer> (); rigid = GetComponent <Rigidbody> (); playerHook = GameObject.Find("HookedIndicator"); hookSprite = playerHook.transform.Find("Sprite").GetComponent <SpriteRenderer> (); jumpAudio = GameObject.Find("Audio").transform.Find("Jump").GetComponent <AudioSource> (); groundLayerMask = new LayerMask[4]; groundLayerMask [0] = LayerMask.GetMask("Object_Default", "Object_Red"); groundLayerMask [1] = LayerMask.GetMask("Object_Default", "Object_Blue"); groundLayerMask [2] = LayerMask.GetMask("Object_Default", "Object_Green"); groundLayerMask [3] = LayerMask.GetMask("Object_Default", "Object_Yellow"); normal = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezePositionZ; frozen = RigidbodyConstraints.FreezePosition | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY; currentSpawnPoint = transform.position; }
public static RigidbodyConstraints GetRigidbodyConstraints(Axis posAxis, Axis rotAxis) { RigidbodyConstraints constraints = RigidbodyConstraints.None; if (!posAxis.HasFlag(Axis.X)) { constraints |= RigidbodyConstraints.FreezePositionX; } if (!posAxis.HasFlag(Axis.Y)) { constraints |= RigidbodyConstraints.FreezePositionY; } if (!posAxis.HasFlag(Axis.Z)) { constraints |= RigidbodyConstraints.FreezePositionZ; } if (!rotAxis.HasFlag(Axis.X)) { constraints |= RigidbodyConstraints.FreezeRotationX; } if (!rotAxis.HasFlag(Axis.Y)) { constraints |= RigidbodyConstraints.FreezeRotationY; } if (!rotAxis.HasFlag(Axis.Z)) { constraints |= RigidbodyConstraints.FreezeRotationZ; } return(constraints); }
//Rigidbody body = GameObject.FindGameObjectWithTag("QB").GetComponent<Rigidbody>(); void Start() { //QB.GetComponent<RigidbodyConstraints.FreezeRotation> (); constraint = RigidbodyConstraints.FreezeRotation; QB.GetComponent <Rigidbody>().useGravity = false; myTransform = transform; }
void CheckConstraints() { RigidbodyConstraints c = RigidbodyConstraints.None; if (ConstrainForceX) { c |= RigidbodyConstraints.FreezePositionZ; } if (ConstrainForceY) { c |= RigidbodyConstraints.FreezePositionX; } if (ConstrainForceZ) { c |= RigidbodyConstraints.FreezePositionY; } if (ConstrainTorqueX) { c |= RigidbodyConstraints.FreezeRotationZ; } if (ConstrainTorqueY) { c |= RigidbodyConstraints.FreezeRotationX; } if (ConstrainTorqueZ) { c |= RigidbodyConstraints.FreezeRotationY; } rb.constraints = c; }
private void Start() { rigidbody = GetComponent <Rigidbody>(); defaultConstraints = rigidbody.constraints; StartCoroutine(WalkForward()); StartCoroutine(WalkInPlace()); }
public void setup(PlayerAction3 act) { colliders = act.GetComponents <CapsuleCollider>(); rbDefaultConstraints = act.rb.constraints; }
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; }
private void DoObjectGrab(object sender, VRTK.InteractableObjectEventArgs e) { //Debug.Log(e.interactingObject.name); //移動、回転、拡縮のconstraintをrigidbodyに適用 RigidbodyConstraints constraint = RigidbodyConstraints.None; if (moveConstraint || type == eNodeType.FK) { constraint |= RigidbodyConstraints.FreezePosition; } if (rotateConstraint) { constraint |= RigidbodyConstraints.FreezeRotation; } targetRigidbody.constraints = constraint; //Debug.Log(targetRigidbody.name); //Grabする前のtransformを記録しておく savedPosition = followTarget.localPosition; savedQuaternion = followTarget.localRotation; savedScale = followTarget.localScale; if (generateNodes.RecordAllChildObjects) { generateNodes.RecordAllGrab(); } grabbing = true; }
void Update() { if (!holding && holdingGameObject) { ResetHolding(); } if (Input.GetButtonDown("Grab")) { if (holding && !playerMovement.lookChanging) { Destroy(holding); ResetHolding(); } else if (!holding) { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, maxDistance, layerMask)) { //Debug.DrawRay( transform.position, transform.right, Color.black, 1f); holdingGameObject = hit.collider.gameObject; holding = holdingGameObject.AddComponent <FixedJoint>(); holding.breakForce = grabForce; holding.connectedBody = rig; if (holdingGameObject.GetComponent <Rigidbody>()) { //m_Rigidbody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationZ; rigidbodyConstraints = holdingGameObject.GetComponent <Rigidbody>().constraints; //holdingGameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ; } } } } }
void Start() { carAudio = GetComponent <AudioSource>(); rb = GetComponent <Rigidbody>(); standart = rb.constraints; player = this.gameObject; if (Informations.isNet) { cam = GameObject.Find("Main Camera"); MobileControl = GameObject.Find("MobileControl"); if (photonView.isMine) { cam.SetActive(photonView); } } if (Informations.isNet && photonView.isMine) { photonView.RPC("SelectColor", PhotonTargets.AllBuffered, Informations.CarId); } else if (!Informations.isNet) { SelectColor(Informations.CarId); } if (Application.platform == RuntimePlatform.WindowsPlayer && !Informations.isDebug) { Destroy(MobileControl); } CamRB = cam.GetComponent <Rigidbody>(); }
private void Awake() { LazyLoadRigidBody(); m_OriginalConstrains = Rigidbody.constraints; currentMovementMode = MovementMode.Forward; }
void Start() { player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>(); playerRigidbody = player.GetComponent<Rigidbody>(); swimConstraints = RigidbodyConstraints.FreezeRotation; }
protected override void Awake() { base.Awake(); // RigidBodyの初期設定を記録 defaultConstraints = rigidbody.constraints; blockRespawnPoint = GetComponentInParent <BlockRespawnPoint>(); }
public void SetConstraints(RigidbodyConstraints constraints) { if (GetComponent <Rigidbody>()) { rigidBody.constraints = constraints; } }
public void StopRecording(float timestamp) { recording = false; cachedConstraints = rb.constraints; rb.constraints = RigidbodyConstraints.FreezeAll; MaybeInvoke(onRecordingStopped); }
private void ApplyLowSpeedFixes() { float verticalInput = input.Vertical; float absVerticalInput = verticalInput < 0 ? -verticalInput : verticalInput; float angVelSqrMag = vehicleRigidbody.angularVelocity.sqrMagnitude; // Increase inertia when still to mitigate jitter at low dt. float t = VelocityMagnitude * 0.35f + angVelSqrMag * 1.2f; float inertiaScale = Mathf.Lerp(5f, 1f, t); vehicleRigidbody.inertiaTensor = inertiaTensor * inertiaScale; if (freezeWhenAsleep && !_isAwake && t + absVerticalInput < 0.2f && _timeSinceSpawned > 2f) { if (freezeWhenAsleep) { vehicleRigidbody.drag = 200f; } if (constrainWhenAsleep && !_constraintsApplied) { _initialRbConstraints = vehicleRigidbody.constraints; vehicleRigidbody.constraints = RigidbodyConstraints.FreezeAll; _constraintsApplied = true; } } else { vehicleRigidbody.drag = Mathf.Lerp(vehicleRigidbody.drag, drag, fixedDeltaTime * 10f); vehicleRigidbody.constraints = _initialRbConstraints; _constraintsApplied = false; } }
/// <summary> /// ///////////////////////////////////////////////// /// </summary> private void Start() { distToGround = collider.bounds.extents.y; particleHyperSpeed = GameObject.FindWithTag("Particle_HyperSpeed"); particleHyperSpeed.SetActive(false); ogRbConstraints = ballRb.constraints; }
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 SetConstraints(RigidbodyConstraints constraints) { if (rigidbody) { rigidBody.constraints = constraints; } }
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; }
private void Start() { vehicleTransform = transform; // Apply initial rigidbody values vehicleRigidbody = GetComponent <Rigidbody>(); vehicleRigidbody.interpolation = RigidbodyInterpolation.Interpolate; vehicleRigidbody.maxAngularVelocity = maxAngularVelocity; vehicleRigidbody.collisionDetectionMode = CollisionDetectionMode.Continuous; vehicleRigidbody.drag = drag; vehicleRigidbody.mass = mass; vehicleRigidbody.angularDrag = angularDrag; vehicleRigidbody.centerOfMass = centerOfMass; vehicleRigidbody.inertiaTensor = inertiaTensor; vehicleRigidbody.sleepThreshold = 0; _initialRbConstraints = vehicleRigidbody.constraints; SetupMultiplayerInstance(); InvokeRepeating("LODCheck", Random.Range(0f, 1f), Random.Range(0.3f, 0.5f)); CheckComponentStates(); // Put to sleep immediately after initializing if (!_isAwake) { Sleep(); } }
void OnDisable() { m_OriginalConstrains = m_Rigidbody.constraints; m_Rigidbody.constraints = RigidbodyConstraints.FreezeAll; EasyJoystick.On_JoystickMove -= OnJoystickMove; EasyJoystick.On_JoystickMoveEnd -= OnJoystickMoveEnd; }
private int oldPosArrayIndex; // 前回の座標配列のインデックス // Use this for initialization void Start() { player = null; playerRigidbodyConstraints = RigidbodyConstraints.None; accelerateFlg = false; oldPosArrayIndex = 0; oldPositionArray = new Vector3[10]; for (int i = 0; i < oldPositionArray.Length; i++) { oldPositionArray[i] = new Vector3(-1, -1, -1); } GetComponent <Rigidbody>().constraints = GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY; wheelRL.motorTorque = 0; wheelRR.motorTorque = 0; wheelFL.motorTorque = 0; wheelFR.motorTorque = 0; }
void OnWandGrab(Transform grabber) { transform.parent = grabber; if (GetComponent<Rigidbody>()) { usedGravity = GetComponent<Rigidbody>().useGravity; GetComponent<Rigidbody>().useGravity = false; constraints = GetComponent<Rigidbody>().constraints; GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; } }
// Use this for initialization void Start () { fall = false; groundedCount = 0; startingPos = transform.position; Moments = new Vector3[2000]; AIStates = new bool[2000]; Moments[0] = transform.position; rigid = GetComponent<Rigidbody>(); standardConstraints = rigid.constraints; }
// Use this for initialization void Start() { free = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY; locked = RigidbodyConstraints.FreezePosition | RigidbodyConstraints.FreezeRotation; sprite = this.GetComponent<Uni2DSprite> (); linkColor = new Color32 (255, 255, 255, 255); freeColor = new Color32 (255, 255, 255, 128); IsLink = true; isLock = false; bodyT=this.GetComponent<SpringJoint> ().connectedBody.transform; }
//Start with bomber deactivated at rest void Awake() { Core = gameObject.GetComponent<Transform>(); PauseAI(); HC = GetComponent<HealthController>(); IC = GameObject.FindGameObjectWithTag("Player").GetComponent<InventoryController>(); P = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>(); RB = GetComponent<Rigidbody>(); floor = P.getCurrentFloor() + 1; Constraints = RB.constraints; RB.constraints = RigidbodyConstraints.FreezeAll; }
private void ToggleBlock(RigidbodyConstraints constraints, GUIContent label, int x, int y, int z) { GUILayout.BeginHorizontal(new GUILayoutOption[0]); Rect position = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, EditorGUILayout.kLabelFloatMaxW, 16f, 16f, EditorStyles.numberField); int id = GUIUtility.GetControlID(0x1c3f, FocusType.Keyboard, position); position = EditorGUI.PrefixLabel(position, id, label); position.width = 30f; this.ConstraintToggle(position, "X", constraints, x); position.x += 30f; this.ConstraintToggle(position, "Y", constraints, y); position.x += 30f; this.ConstraintToggle(position, "Z", constraints, z); GUILayout.EndHorizontal(); }
private void ToggleBlock(RigidbodyConstraints constraints, GUIContent label, int x, int y, int z) { GUILayout.BeginHorizontal(); Rect rect = GUILayoutUtility.GetRect(EditorGUIUtility.fieldWidth, EditorGUILayout.kLabelFloatMaxW, 16f, 16f, EditorStyles.numberField); int controlId = GUIUtility.GetControlID(7231, FocusType.Keyboard, rect); Rect r = EditorGUI.PrefixLabel(rect, controlId, label); r.width = 30f; this.ConstraintToggle(r, "X", constraints, x); r.x += 30f; this.ConstraintToggle(r, "Y", constraints, y); r.x += 30f; this.ConstraintToggle(r, "Z", constraints, z); GUILayout.EndHorizontal(); }
public void Update() { if (playerSwimming) { if (!lowWater) { swimConstraints = (playerIsElephant) ? RigidbodyConstraints.FreezeRotation : RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotation; if (!playerIsElephant) player.transform.position = new Vector3(player.transform.position.x, playerPositionY - (GetComponent<Collider>().bounds.extents.y / 2) + .3f, player.transform.position.z); } else swimConstraints = RigidbodyConstraints.FreezeRotation; } else swimConstraints = RigidbodyConstraints.FreezeRotation; }
private void ConstraintToggle(Rect r, string label, RigidbodyConstraints value, int bit) { bool flag = (value & (((int) 1) << bit)) != RigidbodyConstraints.None; EditorGUI.showMixedValue = (this.m_Constraints.hasMultipleDifferentValuesBitwise & (((int) 1) << bit)) != 0; EditorGUI.BeginChangeCheck(); int indentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; flag = EditorGUI.ToggleLeft(r, label, flag); EditorGUI.indentLevel = indentLevel; if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(base.targets, "Edit Constraints"); this.m_Constraints.SetBitAtIndexForAllTargetsImmediate(bit, flag); } EditorGUI.showMixedValue = false; }
private void OnFracture(OnFractureEventArgs fractureRoot) { Rigidbody body = GetComponent<Rigidbody>(); if (body != null) { body.isKinematic = false; // Need to turn off kinematic to get collision events _rigidBodyVelocity = body.velocity; _rigidBodyAngularVelocity = body.angularVelocity; _rigidBodyConstraints = body.constraints; body.constraints = RigidbodyConstraints.FreezeAll; _impactPoint = Vector3.zero; _impactVelocity = Vector3.zero; _impactMass = 0.0f; _fractureFrame = Time.frameCount; this.enabled = true; } }
public void PickUpItem(GameObject obj) { originalConstraints = obj.GetComponent<Rigidbody>().constraints; isCarryingItem = true; objInRightArm = obj; obj.GetComponent<Pickable>().IsInInventory = false; obj.transform.parent = objectSpaceInHand.transform; obj.transform.position = objectSpaceInHand.transform.position; obj.transform.rotation = objectSpaceInHand.transform.rotation; obj.layer = 2; if (obj.GetComponent<Rigidbody>() != null) { if (obj.GetComponent<Rigidbody>().useGravity) { obj.GetComponent<Rigidbody>().useGravity = false; } obj.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll; } if (!obj.GetComponent<BoxCollider>().isTrigger) { obj.GetComponent<BoxCollider>().isTrigger = true; } }
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; }
void Start() { constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ; }
// Use this for initialization void Start() { S = this; rigid = GetComponent<Rigidbody> (); spRend = GetComponent<SpriteRenderer> (); groundPhysicsLayerMask = LayerMask.GetMask ("Ground"); boxPhysicsLayerMask = LayerMask.GetMask("Boxes"); ladderLayerMask = LayerMask.GetMask ("Ladder"); body = GetComponent<BoxCollider> (); stickTorch = transform.Find("Torch").transform.Find("TorchPointLight").GetComponent<Light>(); stickLight = transform.Find("Torch").transform.Find("TorchPointLight").GetComponent<Collider>(); noRotZ = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ; noRotYZ = noRotZ | RigidbodyConstraints.FreezePositionY; spRend.sprite = spR; GameObject UIGO = Instantiate<GameObject> (UI_Prefab); UI = UIGO.GetComponentInChildren<Text> (); UI.enabled = true; ShowGT (); InvokeRepeating ("DecreaseHealth", 0f, 1f); }
void Start() { constrain = rigidbody.constraints; }
protected override void Awake() { base.Awake(); defaultConstraints = rigidbody.constraints; blockRespawnPoint = GetComponentInParent<BlockRespawnPoint>(); }
public void Pause() { paused = true; oldConstraints = rigidbody.constraints; rigidbody.constraints = RigidbodyConstraints.FreezeAll; }
public override void OnReset() { targetGameObject = null; constraints = RigidbodyConstraints.None; }
void Update() { if(animate) { Transform projectile = null; foreach(Transform child in firingSection.transform) { if(child.tag == "Weapon") { if(child.GetComponent<OrbitingWeapon>() != null) { child.GetComponent<OrbitingWeapon>().orbiting = false; } projectile = child.Find("Projectile"); } } if(animationStage == "fire") { GameObject.FindWithTag("MainCamera").camera.enabled = false; GameObject.FindWithTag("MainMenu").GetComponent<Menu>().on = false; //GameObject.FindWithTag("Help").GetComponent<Menu>().on = false; GameObject.FindWithTag("MainCamera").GetComponent<TowerSelection>().deselectSection(); splitScreen = true; //Set Cameras so it will not display the DamageText //GameObject.FindWithTag("MiniMap").camera.cullingMask &= ~(1 << LayerMask.NameToLayer("DamageText")); firingSection.transform.Find("FireCam").camera.cullingMask &= ~(1 << LayerMask.NameToLayer("DamageText")); firingSection.transform.Find("FireCam").camera.enabled = true; if(hitSections.Count > 0) { firingSection.transform.LookAt(hitSections[0].transform); firingSection.transform.eulerAngles = new Vector3(0, firingSection.transform.eulerAngles.y, 0); defaultConstraints = hitSections[0].rigidbody.constraints; List<Section> hitTowerSects = hitSections[0].GetComponent<Section>().attributes.myTower.GetSections(); for(int i = 0; i < hitTowerSects.Count; i++) { hitTowerSects[i].rigidbody.constraints = RigidbodyConstraints.FreezeAll; } for(int i = 0; i < hitSections.Count; i++) { sectionCams.Add(hitSections[i].transform.Find("HitCam").camera); sectionPos.Add(hitSections[i].transform.position); } hitSections[sectionCounter].transform.Find("HitCam").camera.enabled = true; hitSectionOriginalPosition = hitSections[sectionCounter].transform.position; } else { miss = true; } animationStage = "firePause"; originalProjectilePosition = projectile.position; originalProjectileRotation = projectile.rotation; PlayFiringWeaponSound(); AnimateWeapon(); fireTime = 0; } else if(animationStage == "firePause") { if(fireTime >= pausePeriod) { fireTime = 0; if(hitSections.Count <= 0) { animationStage = "miss"; } else { animationStage = "hit"; } } else { fireTime += Time.deltaTime; projectile.Translate(new Vector3(0, 0, projectileSpeed)); } } else if(animationStage == "hit") { if(sectionCounter < hitSections.Count) { Section hitSection = hitSections[sectionCounter]; hitSection.transform.Find("HitCam").camera.enabled = true; projectile.position = hitSection.transform.Find("ProjectileLocation").position; projectile.LookAt(hitSection.transform); if(sectionCounter != 0) { sectionCams[sectionCounter-1].enabled = false; } hitSectionOriginalPosition = hitSections[sectionCounter].transform.position; GameObject.Instantiate(hitParticle, hitSection.transform.position, hitSection.transform.rotation); //Create Damage Text to display on screen damageText.text = firingSection.GetComponent<Section>().attributes.weapon.GetDamage().ToString(); cloneDamageText = null; if (!firingSection.attributes.weapon.GetEffect().CanAttackSelf()){ cloneDamageText = Instantiate(damageText, damageLocale, Quaternion.identity); PlayWeaponHitSound(); } animationStage = "hitPause"; } else { animationStage = "end"; } } else if(animationStage == "hitPause") { if(fireTime >= pausePeriod) { numShakes = 0; sectionCounter++; animationStage = "hit"; fireTime = 0; if (cloneDamageText != null) Destroy(cloneDamageText); } else { fireTime += Time.deltaTime; projectile.Translate(new Vector3(0, 0, projectileSpeed)); Section hitSection = hitSections[sectionCounter]; sectionCams[sectionCounter].transform.parent = null; if(numShakes <= 10) { hitSection.transform.Translate(new Vector3(shakeSpeed,0,shakeSpeed)); shakeDelta += shakeSpeed; } else { hitSection.transform.position = hitSectionOriginalPosition; } if(Mathf.Abs(shakeDelta) >= Mathf.Abs(shakeSpeed) * 1.5f) { numShakes++; shakeSpeed = -shakeSpeed; shakeDelta = 0.0f; } hitSection.attributes.material.GetSectionEffect().Construct(); hitSection.attributes.weapon.GetEffect().Construct(); } } else if(animationStage == "miss") { AudioSource.PlayClipAtPoint(missSound, new Vector3(0,0,0)); animationStage = "end"; } else if(animationStage == "end") { fireTime = 0; projectile.position = originalProjectilePosition; projectile.rotation = originalProjectileRotation; animationStage = ""; animate = false; GameObject.FindWithTag("MainMenu").GetComponent<Menu>().disabled = false; GameObject.FindWithTag("MainCamera").camera.enabled = true; GameObject.FindWithTag("MainCamera").GetComponent<TowerSelection>().reselectSection(); firingSection.transform.Find("FireCam").camera.enabled = false; splitScreen = false; miss = false; GameObject.FindWithTag("MainMenu").GetComponent<Menu>().on = true; //GameObject.FindWithTag("Help").GetComponent<Menu>().on = true; if(hitSections.Count > 0) { List<Section> hitTowerSects = hitSections[0].GetComponent<Section>().attributes.myTower.GetSections(); for(int i = 0; i < hitTowerSects.Count; i++) { hitTowerSects[i].rigidbody.constraints = defaultConstraints; } for(int i = 0; i < hitSections.Count; i++) { sectionCams[i].transform.parent = hitSections[i].transform; hitSections[i].transform.position = sectionPos[i]; } hitSections[sectionCounter-1].transform.Find("HitCam").camera.enabled = false; } OrbitingWeapon ow = projectile.parent.GetComponent<OrbitingWeapon>(); if(ow != null) { ow.orbiting = true; } } } }
void AttachSpringJoint(RaycastHit hit){ if(springJoint.connectedBody){return;} springJoint.transform.position = hit.point; if (attachToCenterOfMass){ Vector3 anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position; anchor = springJoint.transform.InverseTransformPoint(anchor); springJoint.anchor = anchor; } else{ springJoint.anchor = Vector3.zero; } hook.transform.parent = rb.transform; hook.transform.position = new Vector3(hit.point.x+halfHookScale,hit.point.y+halfHookScale,hit.point.z+halfHookScale); springJoint.connectedBody = hit.rigidbody; oldDrag = springJoint.connectedBody.drag; oldAngularDrag = springJoint.connectedBody.angularDrag; oldX = transform.position.x; oldY = transform.position.y; oldZ = transform.position.z; springJoint.connectedBody.drag = drag; springJoint.connectedBody.angularDrag = angularDrag; oldConstraints = rb.constraints; //will return constraints to values set when game was started...sucks if(restrict.x || restrict.y || restrict.z){ if(restrict.x){ rb.constraints = rb.constraints | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezePositionX; } if(restrict.y){ rb.constraints = rb.constraints | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezePositionY; } if(restrict.z){ rb.constraints = rb.constraints | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezePositionZ; } } if(drawLine && line){ line.visible = true; hook.renderer.enabled = true; } }
// Use this for initialization void Start() { Screen.showCursor = false; screenCenter = new Vector3(Screen.width / 2, Screen.height / 2, 0f); initialConstraints = rigidbody.constraints; animation = GetComponentInChildren<Animation>(); waterClock = (WaterClock)FindObjectOfType(typeof(WaterClock)); facingDirection = Facing.Right; isDead = false; currentStation = null; stationTimer = 0f; }
// Use this for initialization void Start() { startPoint = transform.position; startRotation = transform.rotation; startConstraints = rigidbody.constraints; }
public static void FreezeAllExcept(this Rigidbody rb, RigidbodyConstraints except) { rb.constraints = RigidbodyConstraints.FreezeAll - (int)except; }
void SetCurrentObject(RaycastHit hit){ offset = hit.transform.position - hit.point; if(hit.rigidbody){ rigidBodyKinematic = hit.rigidbody.isKinematic; oldConstraints = hit.rigidbody.constraints; hit.rigidbody.constraints = RigidbodyConstraints.FreezeRotation; hit.rigidbody.isKinematic = true; currentRigidBody = hit.rigidbody; mass = hit.rigidbody.mass; }else{ mass = SimpleDraggable.GetMass(hit.collider); if(mass<=0){mass=1;} } if(deriveDistanceFromMass && mass>0){ maxDistance = strength/mass; } if(!hook){ hook = GameObject.CreatePrimitive(PrimitiveType.Cube); hook.name = "SimpleDraggableHook"; hook.transform.localScale = new Vector3(hookScale, hookScale, hookScale); hook.renderer.material = lineMaterial; hook.renderer.enabled = drawLine; if(!line && drawLine){ line = gameObject.AddComponent("Line") as Line; line.name = "SimpleDraggableLine"; line.width = lineWidth; line.material = lineMaterial; } } hook.transform.position = hit.transform.position - offset; hook.transform.parent = hit.transform; currentObject = hit.transform; old.y = currentObject.position.y; old.x = currentObject.position.x; old.z = currentObject.position.z; if(drawLine && line){ hook.renderer.enabled = true; line.visible = true; } }
void Awake() { initialConstraints = GetComponent<Rigidbody>().constraints; }
void Awake() { originalConstraints = rigidbody.constraints; }
public void SetConstraints(RigidbodyConstraints constraints) { if (GetComponent<Rigidbody>()) { rigidBody.constraints = constraints; } }