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 yusolaifdfer · Feb 22, 2013 at 08:36 AM · playerspherecontrolhead

Controlling a sphere object

I have been trying to make a script that could control a sphere efficiently as a player in the 3D Space without any ground. So far I have tried using rigidbody.addrelativeforce and use the if(input.getkey) to detect if the arrows are pressed to move the sphere around with a code transform.position = transform.position + new Vector3(0,5,0); but when I use that it makes the sphere more violently and it appears like it went up then went back down (but it stays up as I can see the position in inspector)(i have the smoothfollow camera)

and I have tried using a cube as a head and make it rotate when up key is pressed but that doesn't help either

I would really appreciate a help on this. Thank you.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GC1983 · Feb 22, 2013 at 08:49 AM

 public float                     speed;
 public CharacterController         charController;

 void Update()
 {
 var moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
                 charController.Move(moveDirection * Time.deltaTime * speed);
 }

Make sure you have a Character Controller attached. Assign the Char Control to the script. Go to Edit -> Project Settings -> Input. Go down to Vertical and Horizontal. Make sure theyre set to Key and Mouse, and then you can the hotkeys and alternate hotkeys of what each direction will do. You can set it to be directly 2D direction, or 3D.

Youre just having total misunderstanding of what the code does. There are tons of links that relate to this situation. This is common Unity referencing practice.

Hope this helps.

Comment
Add comment · Show 14 · 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 yusolaifdfer · Feb 22, 2013 at 09:28 AM 0
Share

works like magic but what I want to do here is let the sphere move in the Z axis itself with some set velocity and move it freely in the other two axis, that is the sphere will go forward automatically while the user control its up-down and left-right movement

avatar image GC1983 · Feb 22, 2013 at 09:38 AM 0
Share

http://docs.unity3d.com/Documentation/ScriptReference/Input.GetAxis.html

$$anonymous$$aybe set a velocity in one direction and then create the GetAxis to move the other directions that doesnt conflict with its path.

 rigidbody.velocity = new Vector3(xVect, yVect, zVect);
avatar image yusolaifdfer · Feb 22, 2013 at 09:54 AM 0
Share

How would you define the Vertical axis such that ins$$anonymous$$d of moving in Z axis it moves up in the Y axis, if that could be done I can use rigidbody.addrelativeforce to move the sphere in Z axis in the way I would like.

avatar image GC1983 · Feb 22, 2013 at 09:57 AM 0
Share

Thats a setting in the project settings. You can have the settings to move in 2d or 3d space.

avatar image yusolaifdfer · Feb 22, 2013 at 10:24 AM 0
Share

No there isn't, not in the input

Show more comments

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

How to make camera position relative to a specific target. 1 Answer

Camera limitation depending on gravity around sphere 1 Answer

Question about angrybots player controls 1 Answer

Adapt Orientation of player controls to camera? 2 Answers

2D Player Spawn Issue 0 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