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 alok-kr-029 · Feb 16, 2015 at 06:12 AM · raycastlogicwalking

Logic Required

Hi I am making a game in 2d where cahracter can walk on any type of platform that comes in front of him. what I am doing is casting a ray from the character and if it hit the wall I am giving the wall rotation to the character but this logic fails if the wall formed is below the base .You can see the attached image to be clearalt text

please give any idea if you have

screen-shot-2015-02-16-at-113028-am.png (26.0 kB)
Comment
Add comment · Show 3
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 Fewpwew130 · Feb 16, 2015 at 09:09 AM 0
Share

As I understood (correct me if I am wrong) you are trying to make wall-walking game, like Spider-$$anonymous$$an? In this case, maybe, one of many possible solutionsm is to rotate not the wall, but the character.

  • converted my answer to the comment, so you can get more views.

avatar image Kiwasi · Feb 16, 2015 at 09:11 AM 0
Share

Code? Not sure what else we can do to help.

avatar image alok-kr-029 · Feb 16, 2015 at 09:55 AM 0
Share

Can you give any idea so that I can implement this to code . just if you have to make such game how would you approach it .

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by fafase · Feb 16, 2015 at 10:12 AM

Here something to start with.

  • Apply a constant gravity in the current down direction. This way if you are always heading in your feet direction.

  • Have two raycasts at your feet casting front and back at a short distance but long enough to hit the walls.

  • The previous raycasts are used only if you have no collision with your feet.

  • Use the normal of the hit to rotate your character

Now the consequences of that: your guy is standing, it is going down and collides with the ground, nothing special. As you reach the wall to the right, nothing happens. If you jump, the raycast is called, it hits the wall if you are close enough (else nothing happens and you are going down). If it hits the wall, you get the hit.normal and rotate your guy accordingly. At this point you are horinzontal, and gravity is to the right and the jump should have got you far enough from the ground so that the casts are not hitting the ground. You will then naturlly be stuck to the wall by the fake gravity.

You will have to try and tweak until it suits your needs but that should get you started at least.

Comment
Add comment · Show 4 · 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 alok-kr-029 · Feb 16, 2015 at 10:36 AM 0
Share

Great answer As I am also trying somthing like that I am just messed up with gravity part I m not getting how to update the gravity as there can be four condition (0,-9.8),(-9.8,0),(0,9.8),(9.8,0) there will also be other cases like (9.8,9.8) and (-9.8,-9.8) etc Do you have any logic for this or algorithm

To rotate the character I am using

 this.transform.eulerAngles = hit1.collider.transform.eulerAngles;
                 this.transform.parent= hit1.collider.transform;


To give constant velocity in direction of heading

 transform.localPosition = transform.localPosition + new Vector3 (.04f,0,0);



Can you tell me how to get the constant gravity in current down direction . And Do i have to take hit.normal or this will work as its rotating the characrter

avatar image fafase · Feb 16, 2015 at 10:45 AM 0
Share

you don't need to update the gravity if you use the transform.down or -transform.up.

Well, it depends on you process the rotation. If you snap it then right after you can use transform.down. If you lerp it then you might have to wait for the rotation to be done to change the gravity value. All in all, I would not rely on those 4 values you have, just the transform of your object.

Note that transform.up/down are relative to the current rotation which is why you do not need to care about the values you defined.

avatar image fafase · Feb 16, 2015 at 10:47 AM 0
Share

And use AddForce(gravityValue); to get your guy down.

avatar image alok-kr-029 · Feb 17, 2015 at 04:13 AM 0
Share

Thannxxxx fafase it worked . what I did was AddForceRelative . you a developer with very clear logic , Though there are some glitches I will solve it ... Thank once again

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

22 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

Related Questions

3D Grappling Hook Detect Line of Sight Broken 0 Answers

Play different sounds on different surfaces? 1 Answer

Need help with a mirror puzzle script ^^' 1 Answer

Make character walk on walls defying gravity in a 2D Game 1 Answer

Raycasting fail 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