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 delyethsam · Jan 12, 2013 at 05:04 AM · movementplayerwrong

cant find a solution

hi i have been looking on the forums and answers for a while now and i cant find out how to fix the problem im having.

so im making a character move script and im moving it based on the camera rotation. this works fine, but i have my camera on an angle (45 degrees) and the guy always hits the ground when he goes forward and flys when i go back. this is my script:

 using UnityEngine;
 
 using System.Collections;
 
  
 
 public class Move : MonoBehaviour {
 
     
 
     public float WalkSpeed = 10.0f;
 
     public float RunSpeed = 10.0f;
 
     public float jumpHeight = 3.6f;
 
     public float cooldown;
 
     
 
     private bool Grounded = true;
 
     
 
     public Transform camera;
 
     
 
     
 
     // Use this for initialization
 
     void Start () {     
 
         
 
         if(rigidbody)
 
             rigidbody.freezeRotation = true;
 
     }
 
     
 
     void OnCollisionStay(){
 
         Grounded = true;
 
     }
 
     
 
     // Update is called once per frame
 
     void Update () {
 
         
 
         float MoveForward = Input.GetAxisRaw("Vertical") * RunSpeed * Time.deltaTime;
 
         float MoveRight = Input.GetAxisRaw("Horizontal") * RunSpeed * Time.deltaTime;
 
         
 
         //Move The Player
 
         transform.Translate(Vector3.forward * MoveForward, camera);
 
         transform.Translate(Vector3.right * MoveRight, camera);
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 Lovrenc · Jan 12, 2013 at 05:15 AM 1
Share

Title not found.

avatar image delyethsam · Jan 12, 2013 at 06:16 AM 0
Share

title not found?

1 Reply

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

Answer by robertbu · Jan 12, 2013 at 06:46 AM

From this description, I'm not sure of your setup, but it sounds like you have this script either attached to the tilted camera, or to a character who is a child of the tilted camera. Try creating a parent object that has no tilt. The character and the camera can be children with whatever local rotation they need. The movement script would then be attached to the parent object which is only rotated around the Y axis. That way your forward vector will always be parallel to the ground.

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 delyethsam · Jan 12, 2013 at 06:55 AM 0
Share

i forgot to mention sorry about that but the camera can also turn to different angles all around the player so having one parallel wont have that much of an impact. it would work and i am producing a game which that answer will help tho.

avatar image robertbu · Jan 13, 2013 at 05:02 PM 0
Share

Use Transform.localRotation to rotate the camera. The parent object remains level for movement, but the camera tilts/pans relative to the parent object.

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

10 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

Related Questions

Player movement wrong akse 1 Answer

Moving a Simple Ball [Main Player!] inside a tunnel without gravity! 1 Answer

How do you make collider interactions and movement smooth? 0 Answers

Rotation for movement cannot be set in script? 1 Answer

Smooth Player Movement 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