public Move ( |
||
motion | ||
return | CollisionFlags |
static public int Move(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.CharacterController self = (UnityEngine.CharacterController)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 2, out a1); var ret = self.Move(a1); pushValue(l, true); pushEnum(l, (int)ret); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
public void Receive(Variable value, Input _input) { if (_input.InputId == 0) { Set(UnityObjectsConvertions.ConvertToGameObject(value.GetObject())); } if (_input.InputId == 1) { movingVector = new Vector3(movingVector.x, movingVector.y, value.GetFloat()); } if (_input.InputId == 2) { movingVector = new Vector3(value.GetFloat(), movingVector.y, movingVector.z); } if (_input.InputId == 3) { if (controller.isGrounded) { movingVector = new Vector3(movingVector.x, value.GetFloat(), movingVector.z); } } if (_input.InputId == 4) { movingVector.y += UnityEngine.Physics.gravity.y * Time.deltaTime; movingVector = controller.transform.TransformDirection(movingVector); controller.Move(movingVector); movingVector = Vector3.zero; } }
public virtual void Move(Vector3 dist, float deltaTime = 0) { DetectGround(); // ClearHitInfos(); _controller.Move(dist); PostGround(); }
// Origin: Valem, https://www.youtube.com/watch?v=5C6zr4Q5AlA&t=735s&ab_channel=Valem. private void Move() { // Checks whether there is actual input to get teleporting working with joystick movement. if (!(_joystickMovement.axis.magnitude > 0.1f)) { return; } // Move according to direction player is looking at. Vector3 direction = Player.instance.hmdTransform.TransformDirection(new Vector3(_joystickMovement.axis.x, 0, _joystickMovement.axis.y)); _charController.Move(_speed * Time.deltaTime * Vector3.ProjectOnPlane(direction, Vector3.up) - new Vector3(0, 9.81f, 0 * Time.deltaTime)); }
// Default movment mode void Move(Vector2 inputDir, bool running) { float targetRotation; float targetSpeed; Vector3 velocity; // Rotation if (inputDir != Vector2.zero) { targetRotation = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg + camT.eulerAngles.y; transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref turnSmoothVelocity, GetModifiedSmoothTime(turnSmoothTime)); } // Position targetSpeed = ((running) ? runSpeed : walkSpeed) * inputDir.magnitude; currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedSmoothVelocity, GetModifiedSmoothTime(speedSmoothTime)); yVel += Time.deltaTime * gravity; velocity = transform.forward * currentSpeed + Vector3.up * yVel; cc.Move(velocity * Time.deltaTime); currentSpeed = new Vector2(cc.velocity.x, cc.velocity.z).magnitude; if (running && currentSpeed > 0) { stats.ModifyStat("stamina", -Time.deltaTime); } if (cc.isGrounded) { anim.SetBool("Grounded", true); yVel = 0; } else { anim.SetBool("Grounded", false); } }
static public int Move(IntPtr l) { try { UnityEngine.CharacterController self = (UnityEngine.CharacterController)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 2, out a1); var ret = self.Move(a1); pushEnum(l, (int)ret); return(1); } catch (Exception e) { return(error(l, e)); } }
private IEnumerator JumpEvent() { charController.slopeLimit = 90.0f; float timeInAir = 0.0f; do { charController.Move(Vector3.up * Time.deltaTime); timeInAir += Time.deltaTime; yield return(null); } while (!charController.isGrounded && charController.collisionFlags != CollisionFlags.Above); charController.slopeLimit = 45.0f; }
void FixedUpdate() { Move(DirectionVector); CheckTalk(); Vector3 dir = destination - transform.position; // calculate movement at the desired speed: Vector3 movement = dir.normalized * speed * Time.deltaTime; // limit movement to never pass the target position: movement = movement.magnitude > dir.magnitude ? dir : movement; // move the character: cc.Move(movement); }
static public int Move(IntPtr l) { try{ UnityEngine.CharacterController self = (UnityEngine.CharacterController)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 2, out a1); UnityEngine.CollisionFlags ret = self.Move(a1); pushEnum(l, (int)ret); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static int Move(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); UnityEngine.CharacterController obj = (UnityEngine.CharacterController)ToLua.CheckObject(L, 1, typeof(UnityEngine.CharacterController)); UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2); UnityEngine.CollisionFlags o = obj.Move(arg0); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int Move(IntPtr L) { #if UNITY_EDITOR ToluaProfiler.AddCallRecord("UnityEngine.CharacterController.Move"); #endif try { ToLua.CheckArgsCount(L, 2); UnityEngine.CharacterController obj = (UnityEngine.CharacterController)ToLua.CheckObject(L, 1, typeof(UnityEngine.CharacterController)); UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2); UnityEngine.CollisionFlags o = obj.Move(arg0); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
void Update() { verticalSpeed -= gravity * Time.deltaTime; Vector3 movement = moveDirection * moveSpeed + new Vector3(0, verticalSpeed, 0); movement *= Time.deltaTime; float len = impulse.magnitude; if (len > 0.001) { impulse /= len; len -= damping; if (len < 0) { len = 0; } impulse *= len; // impulse *= (1 - Time.deltaTime * C); movement += impulse * Time.deltaTime; } // Move the controller UnityEngine.CharacterController controller = GetComponent <UnityEngine.CharacterController>(); CollisionFlags flags = controller.Move(movement); bool grounded = (flags & CollisionFlags.CollidedBelow) != 0; // We are in jump mode but just became grounded if (grounded && jumping) { jumping = false; SendMessage("OnLand", SendMessageOptions.DontRequireReceiver); } }
// Update is called once per frame void Update() { if (health <= 0) { Die(); } if (impact.magnitude > 0.2) { controller.Move(impact * Time.deltaTime); } impact = Vector3.Lerp(impact, Vector3.zero, 5 * Time.deltaTime); HandleInput(); ItemDescription(); if (health > maxHealth) { health = maxHealth; } healthBar.value = health / maxHealth; }
void FixedUpdate() { float inputX = Input.GetAxis("Horizontal"); float inputY = Input.GetAxis("Vertical"); // If both horizontal and vertical are used simultaneously, limit speed (if allowed), so the total doesn't exceed normal move speed float inputModifyFactor = (inputX != 0.0f && inputY != 0.0f && limitDiagonalSpeed) ? .7071f : 1.0f; if (grounded) { bool sliding = false; // See if surface immediately below should be slid down. We use this normally rather than a ControllerColliderHit point, // because that interferes with step climbing amongst other annoyances if (Physics.Raycast(myTransform.position, -Vector3.up, out hit, rayDistance)) { if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit) { sliding = true; } } // However, just raycasting straight down from the center can fail when on steep slopes // So if the above raycast didn't catch anything, raycast down from the stored ControllerColliderHit point instead else { Physics.Raycast(contactPoint + Vector3.up, -Vector3.up, out hit); if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit) { sliding = true; } } // If we were falling, and we fell a vertical distance greater than the threshold, run a falling damage routine if (falling) { falling = false; if (myTransform.position.y < fallStartLevel - fallingDamageThreshold) { FallingDamageAlert(fallStartLevel - myTransform.position.y); } } // If running isn't on a toggle, then use the appropriate speed depending on whether the run button is down if (!toggleRun) { speed = Input.GetButton("Run") ? runSpeed : walkSpeed; } // If sliding (and it's allowed), or if we're on an object tagged "Slide", get a vector pointing down the slope we're on if ((sliding && slideWhenOverSlopeLimit) || (slideOnTaggedObjects && hit.collider.tag == "Slide")) { Vector3 hitNormal = hit.normal; moveDirection = new Vector3(hitNormal.x, -hitNormal.y, hitNormal.z); Vector3.OrthoNormalize(ref hitNormal, ref moveDirection); moveDirection *= slideSpeed; playerControl = false; } // Otherwise recalculate moveDirection directly from axes, adding a bit of -y to avoid bumping down inclines else { moveDirection = new Vector3(inputX * inputModifyFactor, -antiBumpFactor, inputY * inputModifyFactor); moveDirection = myTransform.TransformDirection(moveDirection) * speed; playerControl = true; } // Jump! But only if the jump button has been released and player has been grounded for a given number of frames if (!Input.GetButton("Jump")) { jumpTimer++; } else if (jumpTimer >= antiBunnyHopFactor) { moveDirection.y = jumpSpeed; jumpTimer = 0; } } else { // If we stepped over a cliff or something, set the height at which we started falling if (!falling) { falling = true; fallStartLevel = myTransform.position.y; } // If air control is allowed, check movement but don't touch the y component if (airControl && playerControl) { moveDirection.x = inputX * speed * inputModifyFactor; moveDirection.z = inputY * speed * inputModifyFactor; moveDirection = myTransform.TransformDirection(moveDirection); } } // Apply gravity moveDirection.y -= gravity * Time.deltaTime; // Move the controller, and set grounded true or false depending on whether we're standing on something grounded = (controller.Move(moveDirection * Time.deltaTime) & CollisionFlags.Below) != 0; }
private void Move() { // set target speed based on move speed, sprint speed and if sprint is pressed float targetSpeed = SprintSpeed; // a simplistic acceleration and deceleration designed to be easy to remove, replace, or iterate upon if (ShouldAim()) { targetSpeed /= 2f; } // note: Vector2's == operator uses approximation so is not floating point error prone, and is cheaper than magnitude // if there is no input, set the target speed to 0 if (_input.move == Vector2.zero) { targetSpeed = 0.0f; } // a reference to the players current horizontal velocity float currentHorizontalSpeed = new Vector3(_controller.velocity.x, 0.0f, _controller.velocity.z).magnitude; float speedOffset = 0.1f; float inputMagnitude = _input.move.magnitude; // accelerate or decelerate to target speed if (currentHorizontalSpeed < targetSpeed - speedOffset || currentHorizontalSpeed > targetSpeed + speedOffset) { // creates curved result rather than a linear one giving a more organic speed change // note T in Lerp is clamped, so we don't need to clamp our speed _speed = Mathf.Lerp(currentHorizontalSpeed, targetSpeed * inputMagnitude, Time.deltaTime * SpeedChangeRate); // round speed to 3 decimal places _speed = Mathf.Round(_speed * 1000f) / 1000f; } else { _speed = targetSpeed; } _animationBlend = Mathf.Lerp(_animationBlend, targetSpeed, Time.deltaTime * SpeedChangeRate); // normalise input direction Vector3 inputDirection = new Vector3(_input.move.x, 0.0f, _input.move.y).normalized; // note: Vector2's != operator uses approximation so is not floating point error prone, and is cheaper than magnitude // if there is a move input rotate player when the player is moving if (_input.move != Vector2.zero || ShouldAim()) { var aimDir = ShouldAim() ? (aimTransform.position - transform.position).ProjOnUp().normalized : inputDirection; _targetRotation = Mathf.Atan2(inputDirection.x, inputDirection.z) * Mathf.Rad2Deg + _mainCamera.transform.eulerAngles.y; var finalRot = ShouldAim() ? Mathf.Atan2(aimDir.x, aimDir.z) * Mathf.Rad2Deg : _targetRotation; float rotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, finalRot, ref _rotationVelocity, RotationSmoothTime); // rotate to face input direction relative to camera position transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f); } Vector3 targetDirection = Quaternion.Euler(0.0f, _targetRotation, 0.0f) * Vector3.forward; // move the player _controller.Move(targetDirection.normalized * (_speed * Time.deltaTime) + new Vector3(0.0f, _verticalVelocity, 0.0f) * Time.deltaTime); // update animator if using character if (_hasAnimator) { _animator.SetFloat(_animIDSpeed, _animationBlend); _animator.SetFloat(_animIDMotionSpeed, inputMagnitude); // var dot = Vector3.Dot(inputDirection, transform.forward); // var direction = Vector3.Dot(inputDirection, transform.right); // _animator.SetFloat(_animIDDot, dot); // _animator.SetFloat(_animIDDirection, direction); // var rightHandLayerIndex = _animator.GetLayerIndex("RightHand"); // var leftHandLayerIndex = _animator.GetLayerIndex("LeftHand"); // var useRight = true; // var leftWeight = !useRight && _input.aimOrFire ? 1f : 0f; // var rightWeight = useRight && _input.aimOrFire ? 1f : 0f; // RightHandAimRig.weight = Mathf.Lerp(RightHandAimRig.weight, rightWeight, // Time.deltaTime * 10f); // _animator.SetLayerWeight(rightHandLayerIndex, // Mathf.Lerp(_animator.GetLayerWeight(rightHandLayerIndex), rightWeight, // Time.deltaTime * 10f)); // LeftHandAimRig.weight = // Mathf.Lerp(LeftHandAimRig.weight, leftWeight, Time.deltaTime * 10f); // _animator.SetLayerWeight(leftHandLayerIndex, // Mathf.Lerp(_animator.GetLayerWeight(leftHandLayerIndex), leftWeight, // Time.deltaTime * 10f)); // HeadAimRig.weight = Mathf.Lerp(HeadAimRig.weight, _input.aimOrFire ? 1f : 0f, Time.deltaTime * 10f); } }
public virtual void Move(Vector3 dist, float deltaTime = 0) { _controller.Move(dist); }
// Update is called once per frame void Update() { if (isDead) { gravity = new Vector3(0, -Gravity, 0); } else { gravity = Vector3.zero; } if (isPingPongActive) { if (walkRight) { transform.rotation = Quaternion.Euler(0, 90, 0); } else { transform.rotation = Quaternion.Euler(0, 270, 0); } charController.Move(this.transform.forward * Time.deltaTime * movingSpeed + gravity); } else { if (Vector2.Distance(player.transform.position, transform.position) < focusRange) { if (!timeToShit.IsRunning) { timeToShit.Start(); } if (timeToShit.ElapsedMilliseconds >= tmpShitTime * 1000) { Instantiate(schissPrefab, schissSpawnPoint.position, schissPrefab.transform.rotation, schissParent); tmpShitTime += (int)bombDropDelay; } if (!anim.GetBool("isWalking")) { anim.SetBool("isIdling", false); anim.SetBool("isWalking", true); } if (transform.position.x - player.transform.position.x > 0) { transform.rotation = Quaternion.Euler(0, 270, 0); } else { transform.rotation = Quaternion.Euler(0, 90, 0); } charController.Move(this.transform.forward * Time.deltaTime * movingSpeed + gravity); } else { if (timeToShit.IsRunning) { timeToShit.Reset(); timeToShit.Stop(); tmpShitTime = 0; } if (anim.GetBool("isWalking")) { anim.SetBool("isIdling", true); anim.SetBool("isWalking", false); } } } }
// Update is called once per frame void Update() { if (!IsDead && mIsControlEnabled) { // Interact with the item if (mInteractItem != null && Input.GetKeyDown(KeyCode.F)) { // Interact animation mInteractItem.OnInteractAnimation(_animator); } // Execute action with item if (mCurrentItem != null && Input.GetMouseButtonDown(0)) { // Dont execute click if mouse pointer is over uGUI element if (!EventSystem.current.IsPointerOverGameObject()) { // TODO: Logic which action to execute has to come from the particular item _animator.SetTrigger("attack_1"); } } // Get Input for axis float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); // Calculate the forward vector Vector3 camForward_Dir = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized; Vector3 move = v * camForward_Dir + h * Camera.main.transform.right; if (move.magnitude > 1f) { move.Normalize(); } // Calculate the rotation for the player move = transform.InverseTransformDirection(move); // Get Euler angles float turnAmount = Mathf.Atan2(move.x, move.z); transform.Rotate(0, turnAmount * RotationSpeed * Time.deltaTime, 0); if (_characterController.isGrounded) { _moveDirection = transform.forward * move.magnitude; _moveDirection *= Speed; if (Input.GetButton("Jump")) { _animator.SetBool("is_in_air", true); _moveDirection.y = JumpSpeed; } else { _animator.SetBool("is_in_air", false); _animator.SetBool("run", move.magnitude > 0); } } _moveDirection.y -= Gravity * Time.deltaTime; _characterController.Move(_moveDirection * Time.deltaTime); } }
// Update is called once per frame void Update() { StopWatchCalculations(); //achivement variable progress PlayerPrefs.SetInt("JUMP", jumpNum); PlayerPrefs.SetInt("HEALTH", medic); PlayerPrefs.SetInt("AMMO", munitions); PlayerPrefs.SetInt("DEATH", deathCounter); PlayerPrefs.SetFloat("DIST", distance); PlayerPrefs.SetInt("GOD", noDeathCounter); PlayerPrefs.SetInt("Presents", presentsFound); PlayerPrefs.SetFloat("TIMER", timer); PlayerPrefs.SetFloat("SECONDS", seconds); PlayerPrefs.SetFloat("MINUTES", minutes); PlayerPrefs.SetFloat("HOURS", hours); int noHitEnable; noHitEnable = noHit ? 1 : 0; if (noHit == true) { PlayerPrefs.SetInt("NOHIT", 1); } else { PlayerPrefs.SetInt("NOHIT", 0); } int EnableTime; EnableTime = showTimer ? 1 : 0; if (showTimer == true) { PlayerPrefs.SetInt("SHOWME", 1); timeText.SetActive(true); } else { PlayerPrefs.SetInt("SHOWME", 0); timeText.SetActive(false); } PlayerPrefs.SetInt("Curr_Health", health); isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask); if (isGrounded && velocity.y < 0) { velocity.y = -2f; pressedJump = false; time = 0; } if (cantMove == false || onLadder == false) { float x = Input.GetAxis("Horizontal"); float z = Input.GetAxis("Vertical"); if (onLadder == false) { Vector3 move = transform.right * x * speed + transform.forward * z * speed + transform.up * velocity.y; controller.Move(move * Time.deltaTime); distance += 0.5f * Time.deltaTime; } if (onLadder == true) { Vector3 moveUp = transform.up * z; controller.Move(transform.up * speed * Time.deltaTime); } //Dash if (Input.GetKeyDown(KeyCode.LeftShift) && canDash == true && x > 0f || Input.GetKeyDown(KeyCode.LeftShift) && canDash == true && x < 0f || Input.GetKeyDown(KeyCode.LeftShift) && canDash == true && z > 0f || Input.GetKeyDown(KeyCode.LeftShift) && canDash == true && z < 0f) { fillDashImage.fillAmount = 1; duration4 = 1; DashEffect.Play(); canDash = false; sound.clip = dashNoise; sound.Play(); StartCoroutine(Dash()); StartCoroutine(DashRecharge()); } } //Jump if (Input.GetButtonDown("Jump") && isGrounded && pressedJump == false && onLadder == false && isDead == false) { velocity.y = Mathf.Sqrt(jumpHight * -2f * gravity); pressedJump = true; jumping.Play(); setPitch(); jumpNum++; } if (pressedJump == false && isGrounded == false && isDead == false) { time += Time.deltaTime; if (time <= maxTime && onLadder == false) { if (Input.GetButtonDown("Jump") && pressedJump == false) { velocity.y = Mathf.Sqrt(jumpHight * -2f * gravity); pressedJump = true; jumping.Play(); setPitch(); time = 0; } else if (time >= maxTime) { pressedJump = true; time = 0; } } } if (onLadder == false) { velocity.y += gravity * Time.deltaTime; } controller.Move(velocity * Time.deltaTime); if (controller.isGrounded == true && controller.velocity.magnitude > 2f && moveNoise.isPlaying == false) { moveNoise.Play(); } if (controller.isGrounded == true && controller.velocity.magnitude < 2f && moveNoise.isPlaying == true) { moveNoise.Stop(); } //achievement stuff if (jumpNum >= 300) { if (!SteamManager.Initialized) { return; } SteamUserStats.SetAchievement("B_Hopper"); SteamUserStats.StoreStats(); PlayerPrefs.SetInt("ACH_12", 1); } if (medic >= 1000) { if (!SteamManager.Initialized) { return; } SteamUserStats.SetAchievement("Combat_Medic"); SteamUserStats.StoreStats(); PlayerPrefs.SetInt("ACH_15", 1); } if (munitions >= 100) { if (!SteamManager.Initialized) { return; } SteamUserStats.SetAchievement("Munition_Man"); SteamUserStats.StoreStats(); PlayerPrefs.SetInt("ACH_16", 1); } if (deathCounter == 1) { if (!SteamManager.Initialized) { return; } SteamUserStats.SetAchievement("Immortality_Is_Overrated"); SteamUserStats.StoreStats(); PlayerPrefs.SetInt("ACH_19", 1); } if (deathCounter == 10) { if (!SteamManager.Initialized) { return; } SteamUserStats.SetAchievement("Maybe_Not_So_Easy"); SteamUserStats.StoreStats(); PlayerPrefs.SetInt("ACH_20", 1); } if (distance >= 666) { if (!SteamManager.Initialized) { return; } SteamUserStats.SetAchievement("Explorer"); SteamUserStats.StoreStats(); PlayerPrefs.SetInt("ACH_13", 1); } if (presentsFound == 1) { if (!SteamManager.Initialized) { return; } SteamUserStats.SetAchievement("What's_This"); SteamUserStats.StoreStats(); PlayerPrefs.SetInt("ACH_22", 1); } if (presentsFound == 6) { if (!SteamManager.Initialized) { return; } SteamUserStats.SetAchievement("The_Collector"); SteamUserStats.StoreStats(); PlayerPrefs.SetInt("ACH_23", 1); } if (fillImageSpeed.fillAmount > 0) { duration -= Time.deltaTime; fillImageSpeed.fillAmount = duration / 20f; } if (fillImageInsta.fillAmount > 0) { duration2 -= Time.deltaTime; fillImageInsta.fillAmount = duration2 / 20f; } if (fillImageInfinite.fillAmount > 0) { duration3 -= Time.deltaTime; fillImageInfinite.fillAmount = duration3 / 20f; } if (fillDashImage.fillAmount > 0) { duration4 -= Time.deltaTime; fillDashImage.fillAmount = duration4 / 1f; } if (health < 30) { dangerScreen.SetActive(true); } if (health >= 30) { dangerScreen.SetActive(false); } //Controls camera bob while moving and jumping if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D)) { camAnim.SetBool("IsMoving", true); } else { camAnim.SetBool("IsMoving", false); } if (isGrounded == false) { camAnim.SetBool("IsMoving", false); } healthText.text = "Health: " + health; if (health <= 0) { //StartCoroutine(respawnTimer()); //health = 5; } if (health > maxHealth) { health = maxHealth; } RaycastHit ray; if (Physics.Raycast(transform.position, -transform.up, out ray)) { if (ray.collider != null) { dropSahdow.transform.position = ray.point; } } if (isDead == true && isDeadArena == false && Input.GetKey(KeyCode.Mouse0) && mouse.unpaused == true && SceneManager.GetActiveScene() != SceneManager.GetSceneByName("ArenaV2")) { Time.timeScale = 1f; ResetPos(); /*health = 50; * point.totalPoints -= 1000; * isDead = false; * freezeMouse = false; * deadText.SetActive(false); * mouse.unpaused = false; * ghost.transform.position = ghostInitialPosition;*/ SceneManager.LoadScene(sceneName); } if (isDead == true && isDeadArena == false && Input.GetKey(KeyCode.Mouse0) && mouse.unpaused == true && SceneManager.GetActiveScene() != SceneManager.GetSceneByName("Arena")) { Time.timeScale = 1f; ResetPos(); /*health = 50; * point.totalPoints -= 1000; * isDead = false; * freezeMouse = false; * deadText.SetActive(false); * mouse.unpaused = false; * ghost.transform.position = ghostInitialPosition;*/ SceneManager.LoadScene(sceneName); } if (Input.GetKey(KeyCode.Escape) && paused == false) { mouse.unpaused = false; Time.timeScale = 0f; paused = true; freezeMouse = true; //mouse.shootReady = false; resumeButt.SetActive(true); quitButt.SetActive(true); settingsButt.SetActive(true); respawnButt.SetActive(true); Cursor.lockState = CursorLockMode.None; } if (impact.magnitude > 0.2F) { controller.Move(impact * Time.deltaTime); } impact = Vector3.Lerp(impact, Vector3.zero, 5 * Time.deltaTime); }
// MovePlayer void MovePlayer(Vector3 move) { m_charController.Move(move * m_finalSpeed * Time.deltaTime); // Moves the GameObject using the Character Controller m_velocity.y += m_gravity * Time.deltaTime; // Gravity effects the jump velocity m_charController.Move(m_velocity * Time.deltaTime); // Actually move the player up }
// Update is called once per frame void Update() { checkForInvincible(); pickupThings(); if (isSwimming) { canDoubleJump = true; swimmingSlider.value = (float)swimmingStopwatch.ElapsedMilliseconds / 1000; if (swimmingStopwatch.ElapsedMilliseconds >= swimmingTime) { swimmingStopwatch.Stop(); getHitFromWater(); } } if (transform.position.y - lastYPos < 0) { isFalling = true; } else { isFalling = false; } lastYPos = transform.position.y; if (lastInput.x > Mathf.Abs(Input.GetAxis("Horizontal"))) { isSlowingDown = true; } else { isSlowingDown = false; } lastInput.x = Mathf.Abs(Input.GetAxis("Horizontal")); // Mathf.Abs gibt den Absolutwerk zurück, immer positiv. move = Mathf.Abs(Input.GetAxis("Horizontal")) * this.transform.forward * Time.deltaTime; if (isSlowingDown && isOnIce && characterController.isGrounded) { if (!slipperingTimer.IsRunning) { slipperingTimer.Start(); } if (slipperingTimer.ElapsedMilliseconds <= 1000) { move = 1 * this.transform.forward * Time.deltaTime; } else { slipperingTimer.Reset(); slipperingTimer.Stop(); isSlowingDown = false; } } else if (isSlowingDown && isOnSticky && characterController.isGrounded) { move = new Vector3(0, 0, 0); } if (Input.GetAxis("Horizontal") > 0) { transform.rotation = Quaternion.Euler(0, 90, 0); } else if (Input.GetAxis("Horizontal") < 0) { transform.rotation = Quaternion.Euler(0, 270, 0); } if (Input.GetKey(KeyCode.LeftShift)) { move *= runSpeed; if (anim.GetBool("isWalking")) { anim.speed = 2f; } } else { move *= walkSpeed; anim.speed = 1; } if (!characterController.isGrounded) { gravity += new Vector3(0, -Gravity, 0) * Time.deltaTime; } else { // LANDED NÖTIG, DA SICH SONST GRAVITATION AUFBAUT, WENN MAN FÄLLT if (landed) { gravity = Vector3.zero; landed = false; } } if (isJumping) { landed = true; gravity = Vector3.zero; gravity.y = JumpForce; isJumping = false; } if (Input.GetButtonDown("Jump")) { if (isPickupActive && currentPickup == Pickups.Jetpack) { } else { if (characterController.isGrounded) { canDoubleJump = true; isJumping = true; } else if (canDoubleJump) { canDoubleJump = false; isJumping = true; } } } move += gravity; if (Delivery_GameManager.currentState == Delivery_GameManager.GameState.playing) { characterController.Move(move); } UpdateAnimation(); transform.position = new Vector3(transform.position.x, transform.position.y, 0); }
void MoveCharacter() { isGrounded.Value = Physics.CheckSphere(collider.bounds.min, 0.1f); if (isGrounded.Value) { if (velocity.y < 0) { velocity.y = 0f; } jumpCount = 0; } Vector3 move = new Vector3(horizontal.Value, 0, vertical.Value).normalized; controller.Move(move * Time.deltaTime * speed.Value); //Quaternion _rotate = Quaternion.identity; //if (move != Vector3.zero && !playerAnimator.Value.GetBool("Aim")) //{ // _rotate = Quaternion.LookRotation(move); // player.Value.transform.rotation = Quaternion.Slerp(player.Value.transform.rotation, _rotate, Time.deltaTime * 100); // //player.Value.transform.forward = move; //} if (doJump.Value) { if (isGrounded.Value) { velocity.y += Mathf.Sqrt(jumpSpeed.Value * 2f * gravity.Value); jumpCount++; } else { if (jumpCount < maxJumpsAllowed.Value) { velocity.y += Mathf.Sqrt(jumpSpeed.Value * 2f * gravity.Value); jumpCount++; } } } if (doDash.Value) { velocity += Vector3.Scale(player.Value.transform.forward, dashDistance.Value * new Vector3((Mathf.Log(1f / (Time.deltaTime * dashDrag.Value.x + 1)) / -Time.deltaTime), 0, (Mathf.Log(1f / (Time.deltaTime * dashDrag.Value.z + 1)) / -Time.deltaTime))); } velocity.y -= gravity.Value * Time.deltaTime; velocity.x /= 1 + dashDrag.Value.x * Time.deltaTime; velocity.y /= 1 + dashDrag.Value.y * Time.deltaTime; velocity.z /= 1 + dashDrag.Value.z * Time.deltaTime; controller.Move(velocity * Time.deltaTime); // Get movement direction var _movement = (player.Value.transform.position - oldPosition); var _dot = Vector3.Dot(player.Value.transform.forward.normalized, _movement.normalized); if (_dot > 0.8f) { // Move forward isMovingBackwards.Value = false; isMovingSideways.Value = false; } else if (_dot < -0.8f) { // Move backward isMovingBackwards.Value = true; isMovingSideways.Value = false; } else if (_dot < 0.2f && _dot > -0.2f) { // Move Sideways isMovingBackwards.Value = false; isMovingSideways.Value = true; } }
void Update() { //control inputs float x = Input.GetAxis(XAxis); float y = Input.GetAxis(YAxis); //check for force crouch bool crouching = (controller.isGrounded && y < -0.5f) || (forceCrouchEndTime > Time.time); velocity.x = 0; //Calculate control velocity if (!crouching) { if (Input.GetButtonDown(JumpButton) && controller.isGrounded) { //jump jumpAudioSource.Stop(); jumpAudioSource.Play(); velocity.y = jumpSpeed; jumpEndTime = Time.time + jumpDuration; } else if (Time.time < jumpEndTime && Input.GetButtonUp(JumpButton)) { jumpInterrupt = true; } if (x != 0) { //walk or run velocity.x = Mathf.Abs(x) > 0.6f ? runSpeed : walkSpeed; velocity.x *= Mathf.Sign(x); } if (jumpInterrupt) { //interrupt jump and smoothly cut Y velocity if (velocity.y > 0) { velocity.y = Mathf.MoveTowards(velocity.y, 0, Time.deltaTime * 100); } else { jumpInterrupt = false; } } } //apply gravity F = mA (Learn it, love it, live it) velocity.y -= gravity * Time.deltaTime; //move controller.Move(new Vector3(velocity.x, velocity.y, 0) * Time.deltaTime); if (controller.isGrounded) { //cancel out Y velocity if on ground velocity.y = -gravity * Time.deltaTime; jumpInterrupt = false; } Vector2 deltaVelocity = lastVelocity - velocity; if (!lastGrounded && controller.isGrounded) { //detect hard fall if ((gravity * Time.deltaTime) - deltaVelocity.y > forceCrouchVelocity) { forceCrouchEndTime = Time.time + forceCrouchDuration; hardfallAudioSource.Play(); } else { //play footstep audio if light fall because why not footstepAudioSource.Play(); } } //graphics updates if (controller.isGrounded) { if (crouching) //crouch { skeletonAnimation.AnimationName = crouchName; } else { if (x == 0) //idle { skeletonAnimation.AnimationName = idleName; } else //move { skeletonAnimation.AnimationName = Mathf.Abs(x) > 0.6f ? runName : walkName; } } } else { if (velocity.y > 0) //jump { skeletonAnimation.AnimationName = jumpName; } else //fall { skeletonAnimation.AnimationName = fallName; } } //flip left or right if (x > 0) { graphicsRoot.localRotation = Quaternion.identity; } else if (x < 0) { graphicsRoot.localRotation = flippedRotation; } //store previous state lastVelocity = velocity; lastGrounded = controller.isGrounded; }
private void Move(Vector3 movementOffset, float deltaTime) { ccModule.Move(movementOffset * deltaTime); }