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
6
Question by SrBilyon · Aug 21, 2010 at 09:34 PM · movementwallgrabclimb

Programming Wall Climbing

Basically, lets say the surface of the wall is "latchable" (which would really be a box collider in my case adjusted to the side of the wall.) I already had assistance with latching onto a ledge and being able to move left and right on it. http://answers.unity3d.com/questions/18430/ledge-hanging-help-box-triggers-are-being-used

I figured in theory that if I copied the code and tweaked it to allow the player to move up and down it would work out. For some reason, it ignores the code that lets me go left and right and now I can only go up and down.

Here is a snippet:

// Wall Movement controls if (onWall && wallTransform) { // Lock camera for short period when transitioning moving & standing still lockCameraTimer += Time.deltaTime; if (isMoving != wasMoving) lockCameraTimer = 0.0;

     // We store speed and direction seperately,
     // so that when the character stands still we still have a valid forward direction
     // moveDirection is always normalized, and we only update it if there is user input.

     //If the camera is behind/beside, right is right. Otherwise, right is left.
    if(Vector3.Dot(Camera.main.transform.forward, transform.forward) < 0)
     moveDirection = h * wallTransform.right;
         else
         moveDirection = h * -wallTransform.right;

         //If the camera is behind/beside, down is down. Otherwise, down is up.
     if(Vector3.Dot(Camera.main.transform.forward, transform.forward) < 0)
     moveDirection =v * -wallTransform.up;
     else
     moveDirection = v * wallTransform.up;

}

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 skovacs1 · Aug 23, 2010 at 02:33 PM 2
Share

I don't think Super $$anonymous$$ario Galaxy has anything to do with it.

1 Reply

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by skovacs1 · Aug 23, 2010 at 02:32 PM

Anyone else reading this likely won't know what h and v are and may not read the linked unityanswer, but that is irrelevant to the problem thankfully and they should still spot the problem easily.

Your problem is simple. You are reassigning the variable instead of adding to its existing value.

moveDirection = h * wallTransform.right;

moveDirection = v * wallTransform.up;

will set moveDirection to v * wallTransform.up;

In order to make the values add to one another, you should change it to

moveDirection += v * wallTransform.up;

Also, you don't need the if(Vector3.Dot(Camera.main.transform.forward, transform.forward) < 0) for the vertical movement. Unless your camera can rotate such that it is upside down (beware of gimbal lock if it can), down will always be down, and otherwise the code is wrong in that instance as it should be if(Vector3.Dot(Camera.main.transform.up, transform.up) < 0).

So your code should look like:

// Wall Movement controls if (onWall && wallTransform) { // Lock camera for short period when transitioning moving & standing still lockCameraTimer += Time.deltaTime; if (isMoving != wasMoving) lockCameraTimer = 0.0;

 //If the camera is behind/beside, right is right. Otherwise, right is left.
 if(Vector3.Dot(Camera.main.transform.forward, transform.forward) &lt; 0)
     moveDirection = h * wallTransform.right;
 else
     moveDirection = h * -wallTransform.right;

 moveDirection += v * wallTransform.up;

}

Also, I recommend that when wall-climbing, you lock the camera in your camera script to be behind the character at all times. It depends on your script, but one easy way is to do the same check as above before moving your camera:

if(Vector3.Dot(target.transform.forward, transform.forward) < 0)
    //move the camera however you are moving your camera
else
    //stop the camera at the closest position/angle behind/beside your target
Comment
Add comment · Show 2 · 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 slidecoast · May 19, 2013 at 12:18 AM 0
Share

I tried to use the code posted but I got some error saying onWall, wallTransform is not defined. But I dont what variables they are. Could you tell me what they are?

avatar image Blaveloper · Mar 03, 2014 at 09:23 AM 0
Share

Booleans. When you see an "if" statement without anything specified (such as "onWall == 1", "onWall > 8"), it's a boolean. "if (onWall)" is the same as "if (onWall == true)". "if (!onWall)" is the same as "if (onWall == false)" (note the use of the exclamation mark).

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

2 People are following this question.

avatar image avatar image

Related Questions

Spider Wall Movement Between Waypoints 1 Answer

Climb Wall: How do I change key input from horizontal to vertical? 2 Answers

Player Climbing a Ladder? 1 Answer

Character controller wall climb mechanic in C# 0 Answers

Bombchu Mechanic 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