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 Henry90 · Mar 06, 2013 at 10:51 AM · cameramovementballslow

How to move a ball "faster" looking from a Camera

Hi everybody, here it is my problem. I'm trying to move my ball correctly but it seems there is something wrong in my code. I have my ball and behind it there is my Main Camera. I used this code to move my ball in relation of the view of my Main Camera:

 public Vector3 forward;
 public Vector3 right;
 public Vector3 moveDirection;
 
 void Update () {
     forward = GameObject.Find("Main Camera").transform.TransformDirection(Vector3.forward);
         forward = forward.normalized;
         right  = new Vector3(forward.z, 0, -forward.x);
         h = Input.GetAxis("Horizontal");
         v=Input.GetAxis("Vertical");
 
         moveDirection  = (h * right  + v * forward)*speed ;
     rigidbody.AddForce(moveDirection);
 }

But the movement is really "slow". I need A LINEAR MOVEMENT. Not a force but I don't know how to apply it. Also when my ball is in air it falls down very slowly. What I'm trying to do is to have a movement like the one in this video: http://kotaku.com/5802589/inmomentum-is-all-about-the-joys-of-movement I suppose that the "addForce" call is a wrong way to do that. If I add a force to my ball and I want to let it change direction, I have to counteract the force acting on my ball and I don't want this. I know that in that video I don't see the Player from behind but the Camera corresponds with the Player view. I don't want this in my game as I explained you before. In my game I have allready put the MouseOrbit script to my Main Camera. What I want is well shown in that video. Can you please help me? Thank you very much!

Comment
Add comment · Show 16
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 06, 2013 at 07:25 PM 0
Share

I watched a portion of your video. I'm not what motion you are talking about. If it is the motion of the camera, then it seems very similar to what is implemented by the example example script for CharacterController.$$anonymous$$ove().

avatar image Henry90 · Mar 06, 2013 at 08:15 PM 0
Share

I just tried that code but it doesn't work.. I mean: 1)according to that video there is a camera who can rotate ($$anonymous$$ouseOrbit) and the player goes where the camera points.. using only the CharacterController.$$anonymous$$ove() it doesn't work because the player movement respect the original coordinates. But I want that he moves according to Camera Coordinates.. as in any normal game.. 2) $$anonymous$$y Camera bounce continuously.. there is nothing more added to my Camera.. only the $$anonymous$$ouseOrbit

avatar image robertbu · Mar 06, 2013 at 08:53 PM 0
Share

I'm confused about what you want. If you want exactly what is in that video, remove $$anonymous$$ouseOrbit from the camera and attach the character controller and the example script to the camera. If you want a 3rd person game, put the CharacterController and the example script on the player in the scene. Then attach the the standard SmoothFollow script to the camera.

avatar image Henry90 · Mar 06, 2013 at 10:57 PM 0
Share

I want a 3rd person game but I want to orbit my camera.. And if I turn right my Camera and press W to move my player, this one has to go where the camera is looking.. But he uses always the original coordinates in that way. Beginning: if I press W the ball moves long my Z axes.. - I turn my camera of 90° on the right for example - If I press W now my player should move long X axis - But no! It keeps moving long the original Z axes And I don't want this! So what I want is: 1) a 3rd person game 2) a mouseOrbit Camera 3) a player$$anonymous$$ovement like in that video

I hope to have been clear this time :S Sorry for my english! Thank you again!

avatar image robertbu · Mar 07, 2013 at 08:54 PM 0
Share

Separate out the motion of the player from the camera motion. Solve the player motion first. Looking at your video indicates that a CharacterController with the script that I reference above gets you 80% of the way there. You will need to change the input to use keys (Input.Get$$anonymous$$ey() most likely), and to make left and right turn rather than "slide," but the feel is the same. Once you get that down, then add the rest.

Show more comments

1 Reply

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

Answer by robertbu · Mar 09, 2013 at 05:06 AM

Here's a new script. The transForward variable needs to be initialized by dragging the camera on top of this variable. The script then utilizes the camera to calculate the forward vector for the object controlled by this script. Just for my own testing, it uses the mouse buttons as well as the arrow keys for forward and backward movement.

 using UnityEngine;
 using System.Collections;
 public class CharHandler : MonoBehaviour {
     public Transform transForward;  // Transform to use for forward movement
     public float speed = 1000.0f;
     public float jumpSpeed = 11.0f;
     public float gravity = 20.0f;
     private Vector3 moveDirection = Vector3.zero;
     private CharacterController controller;
     
     void Start()
     {
         if (transForward == null)
         {
             Debug.Log ("trans not setup");
             transForward = transform;
         }
         controller = GetComponent<CharacterController>();
     }
     void Update() {        
         Vector3 forward = Vector3.Cross (transForward.right, Vector3.up);
         forward.Normalize();
             transform.LookAt (transform.position + forward);
         if (controller.isGrounded) {
             
             moveDirection = Vector3.zero;
             
             if (Input.GetKey (KeyCode.UpArrow) || Input.GetMouseButton (0)) 
                 moveDirection += forward * speed * Time.deltaTime;
             if (Input.GetKey (KeyCode.DownArrow)  || Input.GetMouseButton (1))
                 moveDirection += -forward * speed * Time.deltaTime;
             
             if (Input.GetButton("Jump"))                
                 moveDirection.y = jumpSpeed;                    
         }   
         moveDirection.y -= gravity * Time.deltaTime;        
         controller.Move(moveDirection * Time.deltaTime);    
     }
 }
Comment
Add comment · Show 3 · 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 Henry90 · Mar 09, 2013 at 11:58 AM 0
Share

Well, you really helped me for this question. Thank you a lot for everything you did for me! You script works well. I just needed to do some changes to make it works even when it jumps (I wanted to be able to move even when I was jumping) and it was not a problem. Unfortunately I just realized that I really need a Sphere Collider for my player. This is why I need it: http://www.youtube.com/watch?v=W$$anonymous$$WGAj6CCgE&feature=youtu.be That thing is strange.. for that reason I need a more realistic movement. I tried to apply the Sphere Collider having at the same time the Character Controller but unfortunately it doesn't work. So, thank you really a lot for everything you did for me!:)

avatar image robertbu · Mar 09, 2013 at 03:27 PM 0
Share

I'm sure this is fixable. I don't know character controller well enough to tell you how to fix it. I have some ideas. Google() the list for "stuck character controller" or similar searches and see what you find. If you don't find a solution, post the screen shot of the ball stuck to the side along with a new question. $$anonymous$$y best guess for a solution is to raycast down. If the ray does not hit a platform just under the ball, ignore the isGrounded flag and allow the ball to go down.

avatar image Henry90 · Mar 09, 2013 at 03:56 PM 0
Share

Good. If you tell me that that's fixable I will try to find a solution or I will post a new question. Thank you again!

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

My game is laggy, but there are only a ball and some flat platforms. 3 Answers

"Ballance" Type ball game Problem. 0 Answers

Slow camera move speed? 2 Answers

The sphere goes Slow 1 Answer

I have added a force of 500 and an if statement if the press a certain key they will move a certain way but it does not move I know why it does not but there is another problem. 3 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