Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by pmainpri · Jun 01, 2011 at 08:12 PM · 2daxis

2D Player Movement

Hello, I am trying to construct a 2D platform game based in a 3D world. I want the character to move on platforms that are wrapped around a cube. Each time the player gets to the edge of the cube he will rotate, the camera will switch and player will head around the cube. Thus the game will always be experienced from a 2D perspective but it exists in a 3D world. Now I am having trouble getting the player to move down the z axis at the appropriate time.

The "front" face of the cube (x,y) axis is working fine, but when the character reaches the edge of the cube, he needs to rotate to walk down the "right" side of the cube (z,y) axis. I have been working with the 2D platform tutorial from Unity's website, the one with lerpz, but I have started writing my own movement script using a rigidbody character because the platform controller from the tutorial is above my pay grade and I am having trouble figuring out where to even start. They have the character forced out of the z axis and although I have set up the triggers and the cameras and switching between them works perfectly I cant get lerpz to walk down the z axis after the camera switch has taken place.

So here is the current rigidbody script.

 //variables containing the cameras
 var CubeFaceFront : Camera;
 var CubeFaceRight : Camera;

 //variable setting player movement speed
 var speed = 10;
 
 //Function to activate front camera and disable the rest at game launch
 function start ()
 {
     CubeFaceFront.enabled = true;
     CubeFaceRight.enabled = false;
 }
 
 //Function to detect camera switch trigger collision. And disable/enable appropriate camera.
 function OnControllerColliderHit (hit : ControllerColliderHit)
 {
         if (hit.gameObject.tag == "camswitchR")
         {
             CubeFaceFront.enabled = false;
             CubeFaceRight.enabled = true;
         }
 }
 
 //Function that moves the player in the proper direction according to which camera and cube face is active.
 function Update () 
 {
     if (CubeFaceFront == true && Input.GetKey ("d")) 
     {
         rigidbody.AddForce(Vector3.right * speed * Time.deltaTime);
     }
 
     if (CubeFaceFront == true && Input.GetKey ("a")) 
     {
         rigidbody.AddForce(Vector3.right * -speed * Time.deltaTime);
     }
     if (CubeFaceRight == true && Input.GetKey ("d")) 
     {
         rigidbody.AddForce(Vector3.forward * speed * Time.deltaTime);
     }
 
     if (CubeFaceRight == true && Input.GetKey ("a")) 
     {
         rigidbody.AddForce(Vector3.forward * -speed * Time.deltaTime);
     }    
     
 }

this is setup so that when the rigidbody collides with the camswitchR object the player will turn and, "a" and "d" will move him down the z axis instead of the x axis. however it wont work the character either doesnt move or he goes through the camswitchR object.

Thanks for any help, If this doesnt make any sense I will try to explain the concept more. If someone knows or can help me figure out how to edit the tutorial platform controller script that would be the most optimal but i have been trying to figure out how to edit it for a few days and none of my ideas work. I can post the tutorial platform controller script if that would help. (the original and the edited version with my attempts to liberate the Z axis.

Let me know what can help.

sincerely

pmain

Comment
Add comment · Show 2
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 Chris D · Jun 01, 2011 at 09:06 PM 0
Share

Please try to properly format any (and all) code that you post. If people have a hard time reading your question, they don't tend to give it a second glance.

avatar image pmainpri · Jun 02, 2011 at 01:40 AM 0
Share

i dont know how to do that. I click the button it says enter code here i do but it still posts un formatted.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Meater6 · Jun 15, 2011 at 11:22 PM

Try using the camera's direction. For example, when you press the "d" key, you move right from your current camera's perspective. Once you switch, it then uses the second camera's perspective. You can do this by setting up a Vector3 like this:

 Vector3(Input.GetAxis("Horizontal"), 0, 0);

Then you transform the direction to the cameras perspective like this

 cameraObject.transform.TransformDirection(/*The Vector Above*/)

then you move your character using that vector * speed. I personally have not tried this, but that is how 3rd person controllers work and in theory, works in this scenario.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Play audio on keyboard click? 1 Answer

How do i lock out a axis 1 Answer

Object won't rotate z axis on second click? 2 Answers

Images won't import as sprites? 1 Answer

Need help with rotation script. 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