Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by $$anonymous$$ · Feb 11, 2019 at 03:47 PM · 3dmovement scriptairrestrictmovement

How would I restrict Movement in Air?

I made a Top-down 3D Movement Script where you intentionally can't Jump. But I also don't want, that you can walk in Air. When you're in Air, you should just fall.

This Video shows, how you can move in the Game. And around second 14, it starts showing how you're supposed to be moving. https://youtu.be/Zm2k2PF8BCQ

This is the Script I need help for restricting Movement in Air: using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class Player_Move : MonoBehaviour
 {
     //Movement Variables (Next 3 Code Lines):
     public float walkSpeed;
     private float xInput;
     private float yInput;
     
     //Floor Check Variables (Next 4 Code Lines):
     public Transform floorCheck;
     public float floorCheckRadius;
     public LayerMask floorLayer;
     private bool isOnFloor;
     
     // Start is called before the first frame update
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         //Floor Check Code:
         isOnFloor = Physics.OverlapSphere(floorCheck.position, floorCheckRadius, floorLayer).Length > 0;
         
         //Code to get Input for Player Movement (Next 3 if-Statements):
         if (isOnFloor = true) //Only check for Input if Character is on Floor
             {
             if (Input.GetAxisRaw("Horizontal") != 0)
             {
                 xInput = Input.GetAxisRaw("Horizontal");
                 yInput = 0;
             } else
             if (Input.GetAxisRaw("Vertical") != 0)
             {
                 yInput = Input.GetAxisRaw("Vertical");
                 xInput = 0;
             }
         }else //Hinder Input if Character is not on Floor (This else-Statement):
         {
             xInput = 0;
             yInput = 0;
         }
         
         transform.Translate (xInput * walkSpeed, 0, yInput * walkSpeed); //Make the Player Walk according to Input
         
         //Code to restrict diagonal Movement (Next 2 if-Statements):
         if(Input.GetAxisRaw("Horizontal") == 0)
         {
             xInput = 0;
         }
         if (Input.GetAxisRaw("Vertical") == 0)
         {
             yInput = 0;
         }
     }
 }
 
Comment
Add comment · Show 1
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 TreyH · Feb 11, 2019 at 04:46 PM 0
Share

$$anonymous$$ight want to change:

 if (isOnFloor = true)


to

 if (isOnFloor == true) // or just if (isOnFloor)


variable assignment does return a value, so that's legal syntax and your the compiler won't tell you about it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DehWonderSquid · Feb 27, 2020 at 02:16 PM

You can use isOnFloor to see if its false and have it reduces speed by like *0.90. Then when it returns true it 'll change the speed again.

Comment
Add comment · 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

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

118 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

Related Questions

How can i make my character jump and slide on command? 0 Answers

My movement script is kind of broken for jumping (upward force is diminished after first jump) 1 Answer

sonic movement stick to the ground 1 Answer

How to make a top down character snap to different directions 0 Answers

Want to make GameObject follow another GameObject's path Unity3D 1 Answer


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