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 /
avatar image
0
Question by MC HALO · Jul 03, 2011 at 12:58 AM · fpsfirst-person-controller

FPS Controller Question Again !!

Hey Guys,

I am having some problems with my script basically if i press A the plater will move to the left. But if i press D he will still move to the right why is that?

here is my script:

42 42

public var MoveSpeed: float = 15;

 public var MoveLSpeed : float = 5;
 
 function Update () {
 if (Mathf.Abs(Input.GetAxis("Vertical")) > 0){
      var MoveFWD : float =  Input.GetAxis("Vertical")* Time.deltaTime * MoveSpeed ;
      
      transform.Translate(Vector3.forward * MoveFWD);
 }
 
 if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0){
 
      var MoveLeft : float = Input.GetAxis("Horizontal")* Time.deltaTime * MoveLSpeed;
      transform.Translate(Vector3.left * MoveLSpeed);
 
 }
 }
 
     @script RequireComponent (CharacterController)42

42

I would be really thank full if someone can help me :)

Comment
Add comment · Show 4
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 SisterKy · Jul 31, 2011 at 02:53 AM 0
Share

Dude...! -.- I've been retagging 'unitysomthing' tags for easily over an hour now... and a particularly big share of those single-use-tags were from you.
Everything here is about unity anyway, so why have 'unityfps' additional to 'fps'?
So, please keep in $$anonymous$$d for the future: adding Tags just for fantasy's sake doesn't make any sense and makes a Sister$$anonymous$$y very unhappy =(
Greetz, $$anonymous$$y.

avatar image MC HALO · Jul 31, 2011 at 03:06 AM 0
Share

@Sister$$anonymous$$y Lol sorry about that i will stop that :) i know it is annoying because every question i put up regarding unity FPS i always put those tags sorry :) i will stop that :)

avatar image SisterKy · Jul 31, 2011 at 03:12 AM 0
Share

=D appreciated! =) -- Greetz, $$anonymous$$y.

avatar image MC HALO · Jul 31, 2011 at 03:13 AM 0
Share

@Sister$$anonymous$$y your welcome :)

1 Reply

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

Answer by aldonaletto · Jul 03, 2011 at 01:01 AM

You're making the same mistake as before; you should use MoveLeft instead of MoveLSpeed:

   transform.Translate(Vector3.left * MoveLeft);

EDITED: If you're using a Character Controller, you should move the character using Move. There's a good and simple example in CharacterController.Move - it moves the character, respect collisions, uses gravity and can even jump! Here's a copy of this script:

 var speed : float = 6.0;
 var jumpSpeed : float = 8.0;
 var gravity : float = 20.0;
 
 private var moveDirection : Vector3 = Vector3.zero;
 
 function Update() {
     var controller : CharacterController = GetComponent(CharacterController);
     if (controller.isGrounded) {
         // We are grounded, so recalculate
         // move direction directly from axes
         moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
                                 Input.GetAxis("Vertical"));
         moveDirection = transform.TransformDirection(moveDirection);
         moveDirection *= speed;
         
         if (Input.GetButton ("Jump")) {
             moveDirection.y = jumpSpeed;
         }
     }
 
     // Apply gravity
     moveDirection.y -= gravity * Time.deltaTime;
     
     // Move the controller
     controller.Move(moveDirection * Time.deltaTime);
 }

Comment
Add comment · Show 8 · 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 MC HALO · Jul 03, 2011 at 01:09 AM 0
Share

oh hahahahah i am such an ass lmao :) thanks man i really am blind lol

avatar image MC HALO · Jul 03, 2011 at 01:10 AM 0
Share

oh yeas can you please help me with the gravity thing Please you know if grounded etc and using flags. Please thanks

avatar image aldonaletto · Jul 03, 2011 at 01:16 AM 0
Share

Since your character is a Character Controller, you must not use translate - it ignores collisions. I'm editing my answer to include this matter.

avatar image MC HALO · Jul 03, 2011 at 01:20 AM 0
Share

oh thank you :) i have faced that problem because when i walked next to walls he walked right trough them :) thank you :)

avatar image aldonaletto · Jul 03, 2011 at 01:38 AM 0
Share

Check the answer: it was edited to include a good example script.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

CHARACTER MOVEMENT?! 1 Answer

Standard Asset First Person Controller FPS Problems 0 Answers

Click Once to play an entire animation 2 Answers

How to display Gui for clips left - FPS tutorial 0 Answers

Collider causes terrible lags 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