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 Condore · Nov 09, 2012 at 11:44 PM · rigidbodyvelocityaddforcefixedupdatedash

Setting a delay before dashing.

Hey guys,

Me again. Lol. So the problem I'm facing right now is with our character's dash. I right now it's just bumping up the running speed of our character inside of fixed update and it's working like a dash. The thing is though, is that the transition is so smooth between the two it's almost un-noticable.

What I want to do is have my character stop completely and THEN dash to the direction specified, so that the dash is more apparent. I'll attach my script for all to see. I really don't know how I can do this exactly... any and all help will be appreciated! Thank you!

Condor

 ThirdPersonController.Cs

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class ThirdPersonController : MonoBehaviour
 {
     GameObject player;
     Targetting targetting;
     TP_Animator anim;
     katCollision katanaCol;
     
     public Vector3 movement1 = Vector3.zero;
     
     public Transform myTransform;
     
     public new cameraCode camera;
     
     public bool isAttacking;
     
     //Lock on deselect
     public bool deselectTimer =  false;
     
     public float speed = 1.0f;
     
     //Run Speed, Walk speed, Strafe Speed etc...
     public float runSpeed = 1.7f;
     public float strafeSpeed = 1.5f;
     public float walkSpeedDownscale = 2.0f;
 
     //dodge variables Timer = lifetime, Speed = distance
     public bool isDodging = false;
     public float dodgeTime = 0.25f;
     public float dodgeSpeed = 5.0f;
     
     public LayerMask groundLayers = -1;
         //Make sure that the player is not on the same layer as the environment
     
     private const float inputThreshold = 0.01f;
     public const float groundDrag = 6.0f;
     public const float dragwhileDodge = 2f;
     public float dodgeDrag = 0f;
     public float dodgeRecover = 0f;
     public float isattackingTime;
         
     private bool walking;
     
     public TP_Animator animator;
     
     public AudioSource RunRight;
     public AudioSource RunLeft;
 
     void Start ()
     // Verify setup, configure rigidbody
     {    
         player = this.gameObject;
         
         anim = GetComponent<TP_Animator>();
         
         // find targetting script
         targetting = transform.GetComponent<Targetting>();
         
         myTransform = transform;
 
         rigidbody.freezeRotation = true;
             // We will be controlling the rotation of the target, so we tell the physics system to leave it be
         walking = false;
         
     }
     
     public void Update ()
     {    
         dodgeRecover -= Time.deltaTime;
         isattackingTime -= Time.deltaTime;
         
         if(isattackingTime >= 0.6f)
         {
             isAttacking = true;
         }
         else if(isattackingTime <= 0)
         {
             isAttacking = false;
         }
         
         rigidbody.drag = groundDrag;
         // Apply drag when we're grounded
         
         if(Input.GetButtonDown("Fire1") && isDodging == false && dodgeRecover <= 0f) // dodge
         {
             dodgeRecover = 1.0f;
             
             StopCoroutine("Dodge");
             StartCoroutine("Dodge");
     
             dodgeDrag = groundDrag - dragwhileDodge; 
         }
         
         if(isAttacking == false && isDodging == false)    
         {
             movement1 = new Vector3(Input.GetAxis ("Horizontal") , 0f, Input.GetAxis ("Vertical"));
             movement1.y = 0f;
         }
         
     }
     
     void FixedUpdate ()
     // Handle movement here since physics will only be calculated in fixed frames anyway
     {
     
         if(isAttacking == false)
         {
             float appliedSpeed = walking ? speed / walkSpeedDownscale : speed;
             
             if(Input.GetButtonDown("LockOn"))
             {
                 appliedSpeed = walking ? strafeSpeed / walkSpeedDownscale : strafeSpeed;
             }
             else
             {
                 appliedSpeed = walking ? runSpeed / walkSpeedDownscale : runSpeed;
             }
         
             Vector3 relativeMovement = movement1;
 
             if(targetting.selectedTarget != null)
                 relativeMovement = rigidbody.transform.TransformDirection(relativeMovement);
             else
                 relativeMovement = Camera.main.transform.TransformDirection(relativeMovement);
             
             relativeMovement.y = 0f;
             
             rigidbody.AddForce (relativeMovement * appliedSpeed, ForceMode.VelocityChange);
         
             if (targetting.selectedTarget == null && relativeMovement != Vector3.zero && !isDodging)
                 transform.forward = relativeMovement.normalized;
         }
     }    
     
     void RunRightNow()
     {
         RunRight.Play();
     }
     
     void RunLeftNow()
     {
         RunLeft.Play();
     }
     
     IEnumerator Dodge()
     {
         isDodging = true;
         yield return new WaitForSeconds(dodgeTime);
         isDodging = false;
     }
 
 }
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 sparkzbarca · Nov 10, 2012 at 08:27 AM

http://unitygems.com/mistakes1/#invoke

scroll down to

Make something happen in the future

and

delaying an action

Comment
Add comment · 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

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

10 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

Related Questions

rigidbody velocity on x axis and addforce on y axis ?? 1 Answer

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

slow addforce 1 Answer

Area setting when moving rigidbody 0 Answers

Stopping a rigidbody immediately 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