Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Aug 13, 2021 at 09:58 PM by Silver195 for the following reason:

Other

avatar image
0
Question by Silver195 · Mar 08, 2021 at 10:21 PM · player movement

How can I make it so the player can't move past a certain point?

I want my game coded so that when the player is moving and it is on certain coordinates, it can't go past that point. It will act like an invisible barrier. I want this because my game is coded so that there is a wall that surrounds the map and whenever an object with a Box Collider touches it, it deletes. So when a bullet is fired, it moves until it touches the wall and deletes. But the thing is that the player can move and hit this wall and it deletes the player. So I want to see if I can get it so the player can't move to the wall that deletes things. I do have a movement script for the player so I want to see if I can attach some code to the movement script to get it to work.

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

2 Replies

  • Sort: 
avatar image
1

Answer by Andrajoso · Mar 08, 2021 at 11:37 PM

You could do as Jopa pointed above or scripting the wall collider so it only deletes some kind of GameObjects according to names, tags or whatever you want. I'd use "OnTriggerEnter" to do this.

Comment
Add comment · Show 9 · 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 Silver195 · Mar 09, 2021 at 04:13 AM 0
Share

How do I make it so it destroys a game object by tag?

avatar image Jopa-Przemyslaw Silver195 · Mar 09, 2021 at 07:26 AM 0
Share

Inside method OnCollisionEnter or trigger enter (depends what you have) try adding sth like this void OnTriggerEnter(Collider collider) { if(collider.gameObject.tag != "Player") { //delete } } It should filter the deletion and omit the player.

avatar image Silver195 Jopa-Przemyslaw · Mar 10, 2021 at 04:19 AM 0
Share

I replaced the "Player" part with the tag name and it still has the error "error CS1012: Too many characters in character literal". This is the only error I'm getting so hopefully there is an easy fix.

Show more comments
avatar image
0

Answer by Jopa-Przemyslaw · Mar 08, 2021 at 10:36 PM

Add collider to the player as well as the wall. You don't have to script it, let the engine handle it for you. The only thing you should script is adding an exception for a player not to be deleted.

Comment
Add comment · Show 3 · 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 Jopa-Przemyslaw · Mar 11, 2021 at 12:34 PM 0
Share

This script could use OnTriggerEnter method and should look like this:

 void OnTriggerEnter(Collider other)
 {
     if (other.gameobject.tag != "arrow") 
     {
         //delete
     }
 }

And it won't remove this "arrow" For more read docs: link to OnTriggerEnter documentation.

avatar image AbandonedCrypt Jopa-Przemyslaw · Mar 11, 2021 at 12:38 PM 0
Share

You're trying to declare a method like a variable. It should have the return type 'void' before the method name.

avatar image Jopa-Przemyslaw AbandonedCrypt · Mar 11, 2021 at 12:45 PM 0
Share

Yea, ofc it should, just added that 'void' so that everyone understands it for sure.

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

Why does my fps controller's motion get disabled after it collides with an enemy cube? 0 Answers

Copter movement 1 Answer

Trouble creating knockback when setting velocity on RigidBody2D 0 Answers

How to set NavMeshAgent to move acording to own gameObject.tranform.forward? 1 Answer

Help Rotating a Player 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