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 /
This question was closed Nov 23, 2016 at 09:26 PM by drhodes62494 for the following reason:

Other

avatar image
0
Question by drhodes62494 · Nov 24, 2016 at 04:23 AM · player movementcamera rotatecontrolscamera movementrigidbody.addforce

Using Camera Y Rotation to Determine Player Movement Direction

I am looking looking to use rigidbody.addforce to push a ball (player) around the board. I am using stock the Mouse Orbit on my main camera and the control script show below on my player.

The issue I am encountering is the when I use transform.TransformDirection(movement), it is using the rotation of the camera around the X axis as well as the Y axis. This is causing the force being applied to push the ball slightly down and forward rather than just forward. This results in the forward movement of the ball being slower and the other directions (Strafing and Reverse).

I am looking for a way to only use the rotation of the Camera around the Y axis so that it applies the force in just the forward direction and not down. I have looked for something that can do this but have had no luck.

Any help is appreciated. Thanks!

using UnityEngine; using System.Collections;

public class Player_Controller : MonoBehaviour { private Rigidbody rb; private float speed;

 public float jump;
 private bool canJump;

 public Transform playerCamera;

 void Start()
 {
     rb = GetComponent<Rigidbody> ();
 }

 void OnCollisionEnter (Collision collision)
 {
     canJump = true;
     speed = 400;
 }

 void FixedUpdate ()
 {
     if (canJump == true) 
     {
         if (Input.GetKeyDown (KeyCode.Space)) 
         {
             rb.AddForce (new Vector3 (0, jump, 0));
             speed = 200;
             canJump = false;
         }
     }

         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
         
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
         movement = playerCamera.transform.TransformDirection(movement);

         rb.AddForce (movement * speed * Time.deltaTime);
 }

}

Comment
Add comment
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Creating a file that records the player position during a game in xyz coordinates 0 Answers

Camera relative rigidbody third person player movement 1 Answer

Rigidbody(.addForce) doesn't work with Physic material 1 Answer

I'm a bit new but when my camera rotates with the player model to look around it kind of jitters 0 Answers

Stop and object from moving faster after a specific speed is reached? 2 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