Search Unity

FPS Controller Setting up help

Discussion in 'Scripting' started by ddulshan, Jan 10, 2015.

  1. TheSniperFan

    TheSniperFan

    Joined:
    Jul 18, 2013
    Posts:
    712
  2. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    Sorry for taking long to reply, here's what I currently have, but the moveTime is not increasing when pressed Horizontal or Vertical. :confused:

    Code (JavaScript):
    1. var moveTime : float = 0;
    2. var runWaitTime : float = 2;
    3.  
    4. function Update ()
    5. {
    6.     if(Input.GetButton("Vertical") || Input.GetButton("Horizontal"))
    7.     {
    8.         moveTime = moveTime + 0.5;
    9.     }
    10.    
    11.     if(moveTime >= runWaitTime)
    12.     {
    13.         audio.PlayOneShot(normalSteps[Random.Range(0,normalSteps.Length)]);
    14.         moveTime = 0;
    15.     }
    16. }
     
  3. TheSniperFan

    TheSniperFan

    Joined:
    Jul 18, 2013
    Posts:
    712
    You're increasing moveTime incorrectly. Instead of increasing it by some constant value (0.5f here), you need to factor in the amount by which the player has moved.

    You need to be careful about what you put in your Update() functions, since they're dependent on where they run. This means that the steps will be heard in quicker succession the faster the computer it's running on is. In your specific case, increasing the moveTime by 0.5f is far too much. Assuming your game is simple, you're probably running at +100 frames per second. In one second moveTime would reach 50.0f, meaning that it reaches runWaitTime and get's reset to 0.0f again 25 times per second.
    This is not what you want.

    You'll need to factor in the distance by which the player has moved. Then yo can set runWaitTime to what would be a logical size for a single step.
     
  4. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    Lol, I was thinking the same about calling that 0.5 every frame, and will it Depends on the speed of a Computer.

    And how am I gonna include the Distance walked?
     
  5. TheSniperFan

    TheSniperFan

    Joined:
    Jul 18, 2013
    Posts:
    712
    Find out yourself. I don't intent to write everything for you. ;)
    It's really, really, really simple, so you should figure it out by yourself.
     
  6. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    No, I just need to know HOW to do. Not to write the code for me.
     
  7. TheSniperFan

    TheSniperFan

    Joined:
    Jul 18, 2013
    Posts:
    712
    It's really easy.
    The distance you travelled is the difference between your position last frame and now. ;)
     
  8. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    Ahhh:confused: I'll try. Lol
     
  9. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    Ahhhhh :mad: I tried everything I know and get a feeling on how to do it but I can't get the right line. It's with Transform or Translate right? I tried both but I cant get it right! Here's wat I've done so far.

    Code (JavaScript):
    1. var playerP : GameObject;
    2. var moveTime : float;
    3.  
    4. function Start ()
    5. {
    6.     playerP = GameObject.FindGameObjectWithTag("Player");
    7. }
    8.  
    9. function Update ()
    10. {
    11.     if(playerP.transform.Translate)
    12.     {
    13.         moveTime = moveTime + 0.5;
    14.     }
    15. }
    The moveTime gets update even when the playerP is at still!
    Please, please, pleeeeeaase help! :(
     
  10. TheSniperFan

    TheSniperFan

    Joined:
    Jul 18, 2013
    Posts:
    712
    It looks like you have absolutely no clue of what you're doing.
    Take a few steps back and learn programming first, then get accustomed to the Unity API.

    Learn to walk before you try to run.
     
  11. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    I'm going through those very hard, and I faced another Problem. I have a Object which has 3 Materials in it. And I need to change the "2nd Material (Element 1)" to another. I have added a Bool to trigger the change time. I don't know how to do assign it to the "2nd Material", so here's what I've set up so far.

    Code (JavaScript):
    1. var matOn : Material; // A material I need to assign
    2. var matoff : Material; // Another material I need to assign
    3.  
    4. var changeMat : boolean; // Bool to trigger the Change
    5. var obj : GameObject; // Object having the 3 Materials
    6.  
    7. function Update ()
    8. {
    9.     if(changeMat)
    10.     {
    11.         obj.renderer.material = matOn; // I need to change the 2nd Material to matOn!!! :(
    12.     }
    13.     else
    14.     {
    15.         obj.renderer.material = matoff; // I need to change the 2nd Material to matOn!!! :(
    16.     }
    17. }
     
  12. TheSniperFan

    TheSniperFan

    Joined:
    Jul 18, 2013
    Posts:
    712
  13. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    Yeah, I went through it, but couldn't find wat I was looking for. I need to change ony the 2nd Material who has 3 Materials. How to select only the 2nd Element?
     
  14. TheSniperFan

    TheSniperFan

    Joined:
    Jul 18, 2013
    Posts:
    712
    Okay, that's enough.

    Let me quote my previous post:
    I won't post in this thread anymore, because you a) have absolutely no clue of programming and b) clearly no intention of changing that.
    1. Forget about Unity.
    2. Learn programming.
    3. Learn some more.
    4. Consider giving Unity another go.
    At the moment you're just wasting other people's and your own time. You don't even know the basics of programming. What do you expect to achieve?
     
  15. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    @TheSniperFan : I'm trying to learn and that's why I'm posting here. Anyway, thanks for your help all this way.

    Thread Closed.
     
  16. TheSniperFan

    TheSniperFan

    Joined:
    Jul 18, 2013
    Posts:
    712
    @DragonWarrior_DnW_ : Okay, I'm going to post here one last time.

    Starting with Unity is a very bad idea. As easy and convenient as Unity is, gamedev is still a very complex subject for the most time.
    You'd be far better off, if you'd learn programming first. Get a stable foundation to build upon. Some of the questions you've asked in this thread are questions no one should ever ask in the Unity forums, on account of them being some of the most fundamental programming questions.
    You absolutely have to know about boolean operators, arrays and the rest.

    Learn the basics of programming, move on to OOP, then come back. You'd be surprised how most of the things will start going your way. ;)
     
  17. ddulshan

    ddulshan

    Joined:
    Mar 16, 2014
    Posts:
    190
    @TheSniperFan : Ok. But I've almost finished my game. :D

    Anyway. I need to learn programming(Not Unity Programming). How do I get started? I mean a good Compiler for C# programming.
     
  18. TheSniperFan

    TheSniperFan

    Joined:
    Jul 18, 2013
    Posts:
    712
    You'd be better off asking this question in the General Discussion board. I'm sure people will point you towards some resources.

    That being said, don't learn C#, learn programming. One of the biggest mistake rookies make, is trying to learn a programming language rather than programming. The language is merely a tool.