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 ryno9788 · Mar 12, 2013 at 02:58 AM · c#movementcontrollerwalkingsprint

My character won't move in C#.

I've translated my controller to C# but I've ran into a little snag that may be little or be gargantuan mass chaos. I must know is the problem the vector3 variable at the top. I believe it was the root of my problem on the other script but I don't see why it would do that. I've checked the values on movedirection and they are changing but my object is not moving. If I haven't been clear enough or you need help deciphering my script leave a comment. If anyone can see the problem or can help to narrow it down please help I know my script is a mess.

 public float currentSpeed;
 public float walkSpeed = 6.0f;
 public float maxSpeed = 15.0f;
 public bool swiming = false;
 public bool climbing = false;
 public float rotateSpeed = 100.0f;
 public bool checker  = false;
 public Vector3 moveDirection = Vector3.zero;
 public float jumpSpeed = 8.0f;
 public float sprintCurHealth = 0f;
 public int sprintMaxHealth = 50;
 private int _PercentFull = 100;
 public bool isSprinting = false;
 float gravity = 20.0f;
 
 private bool grounded = false;
 static bool allowMove = true;
 static bool playerSneaking = false;
 void Awake (){
 sprintCurHealth = sprintMaxHealth;
 }
 void Update(){
 if (isSprinting){
 currentSpeed = maxSpeed;
 }
 else {
 currentSpeed = walkSpeed;
 }
 if (Input.GetKey("left shift")){
 if (Input.GetKey("w")){
 if (sprintCurHealth > 0){
     isSprinting = true;
 }
 if (sprintCurHealth <= 0){
     isSprinting = false;
 }}
 }
 if (sprintCurHealth > sprintMaxHealth){
 sprintCurHealth = sprintMaxHealth;
 }
 if (isSprinting){
 sprintCurHealth =- Time.deltaTime;
     }
 if (!isSprinting){
 sprintCurHealth =+ Time.deltaTime;
     }
 
 
 transform.Rotate(0,Input.GetAxis("Mouse X") * rotateSpeed * Time.deltaTime, 0);
 }
 
 void FixedUpdate() {
    if (Input.GetKeyDown("q")){
  //moveDirection.y = jumpSpeed;
 animation.Play("roll");
 //Roll();
  
 }
 if(allowMove){
  
 if (grounded) {
 moveDirection = new Vector3(Input.GetAxis("Horizontal")*currentSpeed, 0, Input.GetAxis("Vertical")*currentSpeed);
 moveDirection = transform.TransformDirection(moveDirection);
        
 moveDirection *= currentSpeed;
 if(!swiming){
 if (Input.GetButton("Jump")) {
 moveDirection.y = jumpSpeed;
             
 }
 if (Input.GetKeyDown("q")) {
       
 moveDirection.y = jumpSpeed;
 //Roll();
 }
 }
 }
 else if (climbing){
   
 moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"),0);
 moveDirection = transform.TransformDirection(moveDirection);
 moveDirection *= currentSpeed;
     
 }
 }
 if(swiming){
 currentSpeed = walkSpeed;
 }
 }
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 Higgenbothom · Mar 14, 2013 at 09:21 PM

First off, it's really hard to debug codeif it's written like this, so I took some time and tabbed everything to their respective places (and changed some code here and there).

As for the bug your script has: I'm not behind a PC with unity right now, but it may be because you use a Vector3 to calculate the position of the player (a proxy), but you never apply the proxy to the position anywhere in the script.

just put this line of code after the final if(Swimming==true) statement and see if that fixes it. I allready put where it should, but commented out.

 transform.position+=moveDirection;

If I have the time, I may get back on this and see if I can get it working.

GLHL

EDIT: For script look in comment

Comment
Add comment · Show 2 · 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 Higgenbothom · Mar 14, 2013 at 10:05 PM 0
Share

Tested it in unity, and setting grounded to true, among others, fixed it for me. The final script can be found at the pastebin below.

Pastebin

avatar image ryno9788 · Mar 14, 2013 at 11:12 PM 0
Share

Thank you ill have to try it out and it looks great

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

11 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 avatar image

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Character moving forwards before pressing anything 0 Answers

CharacterController Jump from moving platform. 0 Answers

How to make a good PlayerMovement 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