• 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 vulgarknight · Mar 08, 2013 at 02:11 AM · transformpositionlocal

transform.position uses wrong position

I am working on a mechanic in my game to let my character climb walls. The character approaches the wall and presses e to "grab" it. The player's position is locked onto an invisible box when climbing, but if i use a box that is rotated, the character gets locked into the wrong position because it is rotated. How can I apply my code to allow for the player to start climbing with a wall rotated in any direction?

Comment
Add comment · Show 7
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 robertbu · Mar 08, 2013 at 02:18 AM 0
Share

is the "invisible box" a box collider or something else? Can't you just rotate the box to match the rotation of the wall? $$anonymous$$ore info please.

avatar image vulgarknight · Mar 08, 2013 at 04:14 AM 0
Share

Sorry. Ok: The wall that you can climb is just a cube with a collider. I made an invisible cube with a collider that is tagged as climbWallActivator that gets recognized with a raycast from the center of the camera (the game is all first person) in front of this wall, I have another invisible cube that has no collider that is used as the climbWallPosition, the reference that positions my character when climbing is initiated. The problem is that the climbWallPosition has to be as wide as the climbable surface so that the character can start climbing from anywhere. $$anonymous$$eep in $$anonymous$$d that this is in a prototyping stag, so most of my problems are really just me foreseeing issues when I begin level design. I am focusing on modularity so I can design the rest of my game with less hitches.

avatar image robertbu · Mar 08, 2013 at 04:35 AM 0
Share

What you doing sounds fine. So were does the problem come in? If it is the position, of the "climbWallPosition" must be at same place the climber climber? If so, can't you adjust it using the raycast data?

avatar image Professor Snake · Mar 08, 2013 at 04:52 AM 0
Share

It would be lovely to be able to take a look at your code for this.

avatar image vulgarknight · Mar 08, 2013 at 05:21 AM 0
Share

Here's some code, I was going to post it in the last comment, but I had to change machines.

$$anonymous$$ouse look script that receives the tag and assigns the z variable:

 else if (centerHit.collider.tag == "climbWall"){
     onClimbWall = true;
     onDoor = false;
     onLedgeGrab = false;
     climbBox = selectedObject.transform.Find("climbBox");
     climbBoxZ = climbBox.transform.position.z;
             }

$$anonymous$$ovement script that receives the z position and moves the player accordingly:

 if (isClimbing) {
             
     climbBoxZ = cameraObject.GetComponent<mouseLook>().climbBoxZ;
 grounded = false;
             
     climbing$$anonymous$$ovement = new Vector2 (rigidbody.velocity.x, rigidbody.velocity.y);
             
     if (climbing$$anonymous$$ovement.magnitude > maxClimbSpeed) {
                 climbing$$anonymous$$ovement.Normalize();
                 climbing$$anonymous$$ovement *= maxClimbSpeed;
             }
             
             rigidbody.velocity = new Vector3(climbing$$anonymous$$ovement.x, climbing$$anonymous$$ovement.y, rigidbody.velocity.z);
             
             transform.position = new Vector3(transform.position.x, transform.position.y, climbBoxZ);
             rigidbody.constraints = RigidbodyConstraints.FreezePositionZ;


Sorry if my paste didn't format right, I can't really tell if the "code" button is on.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

C# Creating a More Efficient Script 4 Answers

Need enemy to follow only active character 0 Answers

Drawing a (debug) line between anchored UI element and mouse? 0 Answers

I need help with the location of instatiated objects on the scene and correct interaction with this 2 Answers

How to move an object to your current positon? 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