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 stevey93 · Mar 04, 2013 at 04:07 PM · movementterrainthird person controller

Third person camera, movement on terrain

Hey guys, i'm quiet new to unity, but not to programming. I am trying to make a simple third person game and already have problems with the camera and the movement on terrain. So the camera should always be behind the player and you change the direction of the player by turning arround the mouse. Then you can move with wasd. The problem with the camera is, that it kinda shakes. The problem about movement is, that i need to walk on terrain or just angular planes but also need walls, which i can't pass. First thing i tried was manipuating the position of the player directly using translate. Now i could walk on terrain perfectly, but could just walk on top of my walls. Then i tried to manipulate the velocity of my rigidbody so i couldn't pass walls but also couldn't walk up on the terrain. I already looked at the unity projects about third person, but they are way to complicated and i also don't need any animations or stuff like that. Does anyone of you have a piece of code or any tipps on how to do it as simple as possible?

Thanks, stevey

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 nventimiglia · Mar 04, 2013 at 06:16 PM 1
Share

Are you using fixedupdate ? 90% of shaking is from using Update.

avatar image stevey93 · Mar 04, 2013 at 06:40 PM 0
Share

thank you for that tipp, but it didn't solve my problem. Heres the code i use:

 Camera.main.transform.localEulerAngles = new Vector3(Camera.main.transform.rotation.eulerAngles.x, playerParent.transform.rotation.eulerAngles.y, 0); 
 Camera.main.transform.position = playerParent.transform.position; Camera.main.transform.Translate(Vector3.back * 6); 
 playerRotationY = playerParent.transform.rotation.eulerAngles.y; cameraRotationX = Camera.main.transform.rotation.eulerAngles.x; 
 playerRotationY += Input.GetAxisRaw("$$anonymous$$ouse X") * GameConstants.movementCameraSensitivity * Time.deltaTime; 
 cameraRotationX -= Input.GetAxisRaw("$$anonymous$$ouse Y") * GameConstants.movementCameraSensitivity * Time.deltaTime; 
 playerParent.transform.localEulerAngles = new Vector3(0, playerRotationY % 360, 0); 
 Camera.main.transform.localEulerAngles = new Vector3(cameraRotationX % 360, playerParent.transform.rotation.eulerAngles.y, 0);

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · Mar 04, 2013 at 07:05 PM

use charactercontroller and the move commands to move

there are 3 types of movements you can do in unity

teleports- aka anything ending in .position = ....

physics- using the rigidbody components (add force etc)

charactercontroller- non phyics movement BUT INCLUDES collision detection. if you can wrap the collider around your person use this for your game.

then do player.charactercontroller.move(where to go)

Comment
Add comment · Show 1 · 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 stevey93 · Mar 06, 2013 at 01:13 PM 0
Share

ohh, wow i didn't know that something like this existed, but thats exactly what i needed. But now i still got the problem about the shaking camera...

thanks, stevey

EDIT: now i could solve the camera problem on my own. I just had to change the sequenze of the code a little bit and put everything into the lateUpdate method and everything works fine. Heres the code:

 void LateUpdate() {
         playerRotationY = playerParent.transform.rotation.eulerAngles.y;
         cameraRotationX = Camera.main.transform.rotation.eulerAngles.x;
         playerRotationY += Input.GetAxisRaw("$$anonymous$$ouse X") * GameConstants.movementCameraSensitivity * Time.deltaTime;
         cameraRotationX -= Input.GetAxisRaw("$$anonymous$$ouse Y") * GameConstants.movementCameraSensitivity * Time.deltaTime;
         playerParent.transform.localEulerAngles = new Vector3(0, playerRotationY % 360, 0);
 
         Camera.main.transform.localEulerAngles = new Vector3(cameraRotationX % 360, playerRotationY % 360, 0);
         Camera.main.transform.position = playerParent.transform.position;
         Camera.main.transform.Translate(Vector3.back * 6);
     }

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

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

Third Person Controller Movement on Elevated Terrain 1 Answer

Moving a rotated plane in x+z directions with WASD? (bizarre behavior) 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to disable A, S, and D keys for third person player movement 1 Answer

Player walks to the right? 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