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 ThaiThao · Oct 21, 2011 at 03:14 AM · movementfps

Fps player control movement script

Hi there I'm a starter in unity and i came across a problem. Well first of all i dont code all that good, and second i can't get my movement to to follow my camera. Like if i press W i want it to go forward but if i turn the camera i want it to follow that direction. (catch my drift?) Here is my script code

public var MoveSpeed :float = 50; public var jumpSpeed : float = 55; public var MoveDirection = Vector3.zero; public var Gravity :float = 45; public var grounded : boolean = false;

function Start (){ }

function Update () { if( grounded ){ MoveDirection = new Vector3(Input.GetAxis("Horizontal"), 0 , Input.GetAxis("Vertical")); MoveDirection = transform.TransformDirection(MoveDirection); MoveDirection = MoveSpeed ; } if( grounded ) { if(Input.GetKey(KeyCode.Space)){ MoveDirection.y = jumpSpeed; } } MoveDirection.y -= Gravity Time.deltaTime; var Controller = GetComponent(CharacterController); var Flags = Controller.Move( MoveDirection * Time.deltaTime); grounded = (Flags & CollisionFlags.CollidedBelow) !=0; }

Comment
Add comment · Show 3
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 BluEye · Apr 16, 2012 at 03:49 PM 0
Share

@ThaiThao and @Aldo Naletto did the above script work?

If so what exactly is the whole script? Did you just copy and paste that into the FPS controller script?

Sorry I'm a newbie and have never messed with JS before and am trying to compare between each one and seeing how things change. I'd very much appreciate if someone help me with this. $$anonymous$$y head is killing me trying to understand all this.

$$anonymous$$uch thanks :D

avatar image ThaiThao BluEye · Apr 17, 2012 at 03:05 AM 0
Share

no i wrote that script.. but it's all fixed already ^^ it worked the first time but the movement wasn't following the camera.. but i wrote another script to fix it.. to pair the camera direction with the movement direction

avatar image BluEye · Apr 18, 2012 at 07:48 PM 0
Share

Would you $$anonymous$$d sharing with me exactly what you wrote? How you implemented it and so forth? I'm not sure what I keep doing wrong but it is very frustrating.

$$anonymous$$uch Thanks.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Oct 21, 2011 at 04:01 AM

You can do that with a few changes: add the variable turnSpeed and modify the beginning of the Update function:

... var turnSpeed: float = 60;

function Update(){ transform.Rotate(0, turnSpeed*Input.GetAxis("Horizontal")Time.deltaTime, 0); if( grounded ){ MoveDirection = new Vector3(0, 0, Input.GetAxis("Vertical")); MoveDirection = transform.TransformDirection(MoveDirection); MoveDirection = MoveSpeed; } ...

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 ThaiThao · Oct 21, 2011 at 04:36 AM 0
Share

sorry but I've tried this and it still doing the same thing... I can move but then again the movement don't follow my camera direction...

avatar image aldonaletto · Oct 21, 2011 at 10:01 AM 0
Share

Well, this is the Doom style move script: the "Horizontal" axis turns the character left/right, and the "Vertical" move it forth/back. It works fine IF the camera is childed to the character AND have no camera script. You can even use $$anonymous$$ouseLook.cs attached to the camera, but with only $$anonymous$$ouse Y control selected. Other camera scripts may not work, since the character doesn't know in which direction the camera is turned.
If you want to control the camera with the mouse, use your original script and attach $$anonymous$$ouseLook.cs to the character - but select only $$anonymous$$ouse X in the Inspector - and attach it also to the camera, this time with only $$anonymous$$ouse Y selected (remove other camera scripts, if any). Anyway, the camera must be a child of the character.

avatar image ThaiThao · Oct 21, 2011 at 11:19 AM 0
Share

perhaps do you have $$anonymous$$mviewer? if you do contact me and i can send you my $$anonymous$$mviewer id and pass.. so you can have a look at what I'm doing wrong because i still can't get it to go the way i want. (email is dtpblk@gmail.com contact me what time you are available and what time area... like U$$anonymous$$ or US or something like that..)

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

Help with fps script 2 Answers

Checking in front of an object before moving 1 Answer

Need to 'un-roll' my FPS 1 Answer

Why is this player script not working 1 Answer

Camera Height-based crouch script 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