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 /
This question was closed Jun 26, 2017 at 09:37 PM by Hamilcar-games for the following reason:

right answer was accepted

avatar image
0
Question by Hamilcar-games · Jun 12, 2017 at 09:39 PM · collisionmovementraycastingplayer movementtags

how to stop player movemnt when there is something near him

im making a crossy road style game and i want that when the player is near a wall i dont want him to move anymore in that direction

so how can i do it without raycasting because sometimes it didnt detect it

or if there is a solution to define the width of the raycasts ?

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

3 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by hassanyawar · Jun 23, 2017 at 11:12 AM

Add a trigger collider in front of player. Give the wall a specific tag like 'Wall'. Use something like this to check:

 void OnTriggerEnter (Collider obj)
 {
        if (obj.CompareTag("Wall"))
        {
               // stop the player
        }
 }
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
avatar image
1

Answer by shadowpuppet · Jun 12, 2017 at 11:21 PM

without raycasting.....you could put trigger zones close to the wall so when player enters he gets a new destination on his navmesh. agent.SetDestination( some object). but ..if he is user controlled isn't up to the player to determine to not go in that direction ( of the wall)

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 Hamilcar-games · Jun 22, 2017 at 08:01 PM 0
Share

thanks for the answer if you can explain in more details to know how to do it exactly step by step

avatar image
0

Answer by IMemeManI · Jun 23, 2017 at 09:11 AM

I'm more of a 3D developer but my guess would be to detect a collision and stop the Player moving forward? Make the object have a collider and the Player script use OnCollisionStay to detect the collision, when it's detected, make the movement forward stop by simply making a bool:

 bool canWalk;
 
 void OnCollisionStay(Collision Coll)
 {
 if(Coll.gameobject.tag == "wall")
 {
 canWalk = false;
 } else
 {
 canWalk = true;
 }
 }


Apply "canWalk" to your movement script so when it detects the input "W" or if it's automated, in the "if" statement make sure you include, "&& canWalk", as if "canWalk" is false, the forward movement will not execute which in turn, stops the Player moving forward as long as the object he collides with has the tag "wall", or whatever you wanna call it.

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

Follow this Question

Answers Answers and Comments

122 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

Related Questions

Stop player running at wall 1 Answer

Reacting to terrain height changes without a rigidbody component 0 Answers

Multitouch and collision for android 0 Answers

Using Raycasts to change the X and Y position of a moving GameObject? 1 Answer

Stopping my player from moving when hitting a wall. 5 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