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 /
avatar image
0
Question by Teleight · Feb 03, 2021 at 10:56 PM · collisionmovement3dtransform.position

Ways to create walls without using rigidbody physics in 3D,Ways to limit a player's movement without rigidbody physics in

Hi, I am currently making a top-down 3D bullet hell (inspired by the 9S hacking minigames in Nier:Automata) and my player uses controller input to move around using transform.position. All of my movement scripts work how I want them to. My issue is that due to the nature of transform.position, collision isn't as straightforward as I'd like it to be. I simply want to be able to create walls that will stop the player when they attempt to move towards them. I want to know what my options are, and if there may just be something I'm missing. I'd like to use raycasts, but I'm unsure how to limit the player's movement once the raycast hits one of my walls, as setting the player's position to hit.point will simply allow them to walk through the wall after they hit it the first time. Any help would be greatly appreciated, thanks.,

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

· Add your reply
  • Sort: 
avatar image
1

Answer by PvtPuddles · Feb 03, 2021 at 11:05 PM

It seems like you're mostly there, and you have a couple options

A) Stop the player from moving entirely if the raycast hits a wall. This will stop the player from moving into the wall, but unfortunately will also mean they cannot slide against the wall. Note that the ray needs to be cast before the player moves so that you can cancel their movement, rather than forcing them to go to a specific position.

B) If your walls are straight, then you can figure out basically a line that represents the wall. When the raycast detects the wall, you can halt any movement the player has perpendicular to the wall.


This should give you a good jumping off point, if it isn't enough I can brush up on the maths behind option B to help you figure it out.

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 Teleight · Feb 04, 2021 at 04:40 AM 0
Share

I like option B, and (after some research) I have used RaycastHit.normal and Vector3.Angle to figure out the angle between my player and the wall they're facing. However I'm unsure on how to create the line to represent the wall (I imagine the answer to this one is staring me in the face), and how to halt their perpendicular movement to it. I appreciate the pointer tho! I was stuck on this all day today and this is my first time using the forums, thanks!

avatar image AbandonedCrypt Teleight · Feb 04, 2021 at 05:55 AM 1
Share

Use Vector3.ProjectOnPlane with the hit.normal to get the perpendicular vector.

avatar image Teleight AbandonedCrypt · Feb 04, 2021 at 07:19 AM 0
Share

Thanks, I got it working somewhat, so far I have taken the hit.normal and added it to my movement script so that the player stops when they face the wall, and that is all working as normal. However I'm not sure how to incorporate ProjectOnPlane, and when you go up to a corner the player can slip through the diagonal between the two walls. I assume the correct application of ProjectOnPlane will fix this?

         RaycastHit hit;
         Ray ray = new Ray(transform.position, leftJoystickDirection);
 
         if (Physics.Raycast(ray, out hit, rayDistance, walls))
         {
             Vector3.Angle(hit.normal, transform.position);
 
             Vector3.ProjectOnPlane(hit.point, hit.normal);

             if (hit.distance >= 0.1f)
             {
                 ic.leftVertical += hit.normal.z;     
                 ic.leftHorizontal += hit.normal.x;
             }

Here is my code so far if that didn't make sense, ic.leftVertical and ic.leftHorizontal stand for the GetAxis("Vertical") and GetAxis("Horizontal"), respectively. Also, as of right now, I am not using the Vector3.Angle code for anything.

avatar image
0

Answer by imanbiku · Feb 04, 2021 at 07:23 AM

jjjjjjjjjjjjjjjjjjjjjjjjjjjjj

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

246 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 to add platform motion to player controller without parenting? - Mostly working code 1 Answer

Make character not move through walls and other objects 4 Answers

Movement based on collision on a custom mesh 0 Answers

How to Have Two Child Objects of One Parent Detect Collisions Between Eachother. 1 Answer

Player getting stuck in ground (3D) player has Rigidbody, and Box Collider, world is Mesh Colliders 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