Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by TacoExpress · Dec 07, 2020 at 08:32 PM · unity 2dplayer movementgrid based gamestealth

"Sneaking" in a Grid Based Movement Game?

I have a 2D stealth game which, before switching to grid based movement, involved slowing the player's movement speed to 1f upon holding left shift to simulate a "sneaking" state. However, when I switched to grid based movement, the player will always move at regular walking speed despite holding shift or not when moving in between grid squares. I'm wondering if it's possible to have something which will slow the walk speed between squares while holding left shift, and if so, how to implement it?

EDIT: Here's the code in question

Looking at this I'm realizing I can probably change to Vector2 since it's a 2D game, but I don't believe that's the problem with regards to slowing down the movement speed. The first few lines in update() would originally slow down the player movement upon holding left shift but no longer works with the grid based movement. Below is an excerpt of how the movement is conducted, there's some other stuff involved in the file which handles collisions but I felt it was irrelevant to the problem I'm having here.

I'm hoping to have the player's transition from one tile to another slow to 1f upon holding shift as opposed to the usual 5f movement speed that it seems to default at.

  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class Player_Movement : MonoBehaviour
  {
      private float moveSpeed = 5f;
      public Transform movePoint;
      public Animator animator;
      public Collider2D coll;
      private float saveHoriz = 0f;
      private float saveVert = 0f;
      void Start() {
          movePoint.parent = null;
      }
  
      void Update()
      {
          if (Input.GetKeyDown(KeyCode.LeftShift)) {
              moveSpeed = 0.1f;
              Debug.Log(moveSpeed);
          }
          else {
              moveSpeed = 5f;
              Debug.Log(moveSpeed);
          }
  
          transform.position = Vector3.MoveTowards(transform.position, movePoint.position, moveSpeed * Time.deltaTime);
  
          if (Vector3.Distance(transform.position, movePoint.position) <= .05f) {
              if (Input.GetAxisRaw("Horizontal") == 1f) {
                  movePoint.position += new Vector3(Input.GetAxisRaw("Horizontal") + .6f, 0f, 0f);
                  saveHoriz = -1.6f;
                  saveVert = 0f;
                  animator.SetFloat("Vertical", 0f);
                  animator.SetFloat("Horizontal", Input.GetAxisRaw("Horizontal"));
                  animator.SetFloat("Speed", movePoint.position.sqrMagnitude);
              }
              else if (Input.GetAxisRaw("Horizontal") == -1f) {
                  movePoint.position += new Vector3(Input.GetAxisRaw("Horizontal") + -.6f, 0f, 0f);
                  saveHoriz = 1.6f;
                  saveVert = 0f;
                  animator.SetFloat("Vertical", 0f);
                  animator.SetFloat("Horizontal", Input.GetAxisRaw("Horizontal"));
                  animator.SetFloat("Speed", movePoint.position.sqrMagnitude);
              }
              else if (Input.GetAxisRaw("Vertical") == 1f) {
                  movePoint.position += new Vector3(0f, Input.GetAxisRaw("Vertical") + .6f, 0f);
                  saveHoriz = 0;
                  saveVert = -1.6f;
                  animator.SetFloat("Horizontal", 0f);
                  animator.SetFloat("Vertical", Input.GetAxisRaw("Vertical"));
                  animator.SetFloat("Speed", movePoint.position.sqrMagnitude);
              }
              else if (Input.GetAxisRaw("Vertical") == -1f) {
                  movePoint.position += new Vector3(0f, Input.GetAxisRaw("Vertical") + -.6f, 0f);
                  saveHoriz = 0;
                  saveVert = 1.6f;
                  animator.SetFloat("Horizontal", 0f);
                  animator.SetFloat("Vertical", Input.GetAxisRaw("Vertical"));
                  animator.SetFloat("Speed", movePoint.position.sqrMagnitude);
              }
          }
      }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KhashayarJan · Dec 07, 2020 at 08:28 AM

There is always a way to do things. But the thing is we have no idea how you implemented your movement and grids and ... .

slow motion can be achieved by setting Time.timeScale to a value between 0 and 1. but that slows the whole scene.

give more information about how you're implementing your movement so we can help better

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TacoExpress · Dec 08, 2020 at 08:33 AM 0
Share

I've added some code to go along with my issue above, hopefully that will suffice

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

222 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Hi everyone I'm trying to make my player double jump but I'm new to C#. Here what I got so far? Can anyone help? 0 Answers

Movement Colliding Improperly In Two Directions 0 Answers

EndLess 2D Game 0 Answers

Player making "random jumps" while is moving at random places (Unity 2D) 0 Answers

Ground check BoxCast is detecting when player hits bottom of platform. UNITY 2D C# 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges