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 windrunner · Jun 30, 2013 at 08:30 PM · animationcontrollergravityspeed

Not Run while Aiming; Slope Terrain Making Object Faster

Hey, I would like to request a little help here, somehow I got stuck with what I think must be really simple to fix and I'm just trying the wrong thing.

I am having two problems here right now.

First is related to a character animation and the speed while moving of that animation.

I use my own custom script, so it might not be complete as I am relatively new to Unity's scripting, used to be part of the art team.

The situation I have is:

I have one character (Player) for a third person game, so I have by default three basic ways to move around:

1) Just walk (A,W,S,D). 2) Run (hold Shift, the ''Run'' Axes). 3) Walk while aiming ( Right Mouse Buttom, the ''Aim'' Axes and A,W,S,D).

Walk and run are working just fine. The problem is the walk while aiming part. For gameplay's sake we don't want the character to be able to run around WHILE aiming, the movement must be the same as the walk part.

The problem is, as much as we were able to easily set up the character to walk while aiming with the walk speed, if we hold down the ''Run'' Axes (Shift) WHILE aiming, the character will then change movement speed to the run speed, not good for us.

I tried some ways to fix this, like using an ''if'' condition, to make the speed equal the walk speed if we hold ''Aim'' AND ''Run', no success, then I tried to set that same condition inside the condition of we holding ''Aim'', no success too.

Last, I set up it so, if we hold Aim and move to any direction we will call another ''if'' condition, checking if we are holding ''Run'', then we move at normal speed. No good.

I am a bit out of ideas now... I would really appreciate if someone could check the code and find the error, or just give me an idea of how to set the condition.

This is the code:

  //Basic movement of an object with Translate
  //This holds the character turning
  //Rotation Variables
  var xSpeed = 250.0;
  var ySpeed = 120.0;
  var yMinLimit = -20;
  var yMaxLimit = 80;
  private var x = 0.0;
  private var y = 0.0;
  //Movement Variables
  private var moveDirection : Vector3 = Vector3.zero;
  private var controller: CharacterController;
  function Start () {
      var controller : CharacterController =

GetComponent(CharacterController); //Getting the character controller

  }
  function Update () {
      var speed : float = 3.0;
      var rotateSpeed : float = 3.0;
          var controller : CharacterController =

GetComponent(CharacterController); //We here handle the walking moviment, considering only the directional buttom is being pressed.

          // Move forward 
          if (Input.GetAxisRaw ("Up"))
          var forward : Vector3 = transform.TransformDirection(Vector3.forward);
          var forwardSpeed : float = speed * Input.GetAxis ("Up");
          controller.SimpleMove(forward *

forwardSpeed);

          // Move Backward 
          if (Input.GetAxisRaw ("Down"))
          var backward : Vector3 = transform.TransformDirection(Vector3.forward);
          var backwardSpeed : float = speed * Input.GetAxis ("Down");
          controller.SimpleMove(-backward *

backwardSpeed);

          // Move Right 
          if (Input.GetAxisRaw ("Right"))
          var right : Vector3 = transform.TransformDirection(Vector3.right);
          var rightSpeed : float = speed * Input.GetAxis ("Right");
          controller.SimpleMove(right *

rightSpeed);

          // Move Left 
          if (Input.GetAxisRaw ("Left"))
          var left : Vector3 = transform.TransformDirection(Vector3.right);
          var leftSpeed : float = speed * Input.GetAxis ("Left");
          controller.SimpleMove(-left *

leftSpeed);

  // Here we make sure that the run animation play if we hold down shift

either with an animation already playing or not

     //Run Forward
               if(((Input.GetAxisRaw ("Run")) && (Input.GetAxisRaw ("Up")))

|| (Input.GetAxisRaw ("Up")) &&
(Input.GetAxisRaw (("Run"))))

          if (Input.GetAxisRaw ("Up"))
          var forwardrun : Vector3 = transform.TransformDirection(Vector3.forward);
          var forwardrunSpeed : float = speed * Input.GetAxis ("Up");
          controller.SimpleMove(forwardrun *

forwardrunSpeed);

      //Run Backward   
               if(((Input.GetAxisRaw ("Run")) && (Input.GetAxisRaw

("Down"))) || (Input.GetAxisRaw ("Down")) && (Input.GetAxisRaw (("Run"))))

          if (Input.GetAxisRaw ("Down"))
          var backwardrun : Vector3 = transform.TransformDirection(Vector3.forward);
          var backwardrunSpeed : float = speed * Input.GetAxis

("Down"); controller.SimpleMove(-backwardrun * backwardrunSpeed);

        //Run Left          
               if(((Input.GetAxisRaw ("Run")) && (Input.GetAxisRaw

("Left"))) || (Input.GetAxisRaw ("Left")) && (Input.GetAxisRaw (("Run"))))

          if (Input.GetAxisRaw ("Left"))
          var leftrun : Vector3 = transform.TransformDirection(Vector3.right);
          var leftrunSpeed : float = speed * Input.GetAxis ("Left");
          controller.SimpleMove(-leftrun *

leftrunSpeed);

         //Run Right               
               if(((Input.GetAxisRaw ("Run")) && (Input.GetAxisRaw

("Right"))) || (Input.GetAxisRaw ("Right")) && (Input.GetAxisRaw (("Run"))))

          if (Input.GetAxisRaw ("Right"))
          var rightrun : Vector3 = transform.TransformDirection(Vector3.right);
          var rightrunSpeed : float = speed * Input.GetAxis ("Right");
          controller.SimpleMove(rightrun *

rightrunSpeed);

  //It is important that the character do not run while aiming.
  //We must set up that the character will only be able to move
  //at the walking speed while aiming
  //Aim and Walk Forward
            if(((Input.GetAxisRaw ("Aim")) && (Input.GetAxisRaw ("Up")))

|| (Input.GetAxisRaw ("Up")) &&
(Input.GetAxisRaw (("Aim"))))

            if (Input.GetAxisRaw ("Run"))
            controller.SimpleMove(forward);      
  //Aim and Walk Backward               
            if(((Input.GetAxisRaw ("Aim")) && (Input.GetAxisRaw

("Down"))) || (Input.GetAxisRaw ("Down")) && (Input.GetAxisRaw (("Aim"))))

            if (Input.GetAxisRaw ("Run"))
            controller.SimpleMove(-backward);   
  //Aim and Walk Left               
            if(((Input.GetAxisRaw ("Aim")) && (Input.GetAxisRaw

("Left"))) || (Input.GetAxisRaw ("Left")) && (Input.GetAxisRaw (("Aim"))))

            if (Input.GetAxisRaw ("Run"))
            controller.SimpleMove(-left);      
  //Aim and Walk Right        
            if(((Input.GetAxisRaw ("Aim")) && (Input.GetAxisRaw

("Right"))) || (Input.GetAxisRaw ("Right")) && (Input.GetAxisRaw (("Aim"))))

            if (Input.GetAxisRaw ("Run"))
            controller.SimpleMove(right);         
  //We must make sure the character will always face the camera so we set

it to rotate along the camera.

   if(Input.GetAxisRaw ("Mouse X"))
          x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
          var rotation = Quaternion.Euler(y, x, 0);
          transform.rotation = rotation;
   }   
  static function ClampAngle (angle : float, min : float, max : float) {
      if (angle < -360)
          angle += 360;
      if (angle > 360)
          angle -= 360;
      return Mathf.Clamp (angle, min, max);
  }
  @script RequireComponent(CharacterController)


This one is my most urgent problem, but there is another one.

I have an idea of what is going wrong here, but I would like someone to make a small check and give me an idea, for I really don't know how to fix this. I found another similar question but it didn't work...

What I have is:

Whenever my character walk down a slope, no matter the angle, it gets some insane speed up. I think what is actually happening is the character is ''falling'', using the gravity power to move at such fast speed.

I tried to chance the slope limit on the character controller, but no real success, this one I really have no idea on how to solve...

For both cases, I use the same controller above.

Here is a video showing what exactly happens ingame:

http://www.youtube.com/watch?v=gq3qYj9W2cI&feature=youtu.be

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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

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

HeadLookController 0 Answers

Apply gravity 2 Answers

Character fall animation 1 Answer

Problem with character movement 2d when attaching animator 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