• 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
Question by Charles_Gams · Mar 27, 2013 at 09:57 AM · movementspeedsnap

Move from point A to point B with a single button press

I'm developing a bounce attack feature just like in sonic and The code so far is looking good. I've got the player only able to bounce attack if its reach a certain jump speed in my code or height logically speaking. However it moves fine but too sudden and i don't want this type of effect.

Initially i want the transition of the movement to be seen at a certain speed rather than a quick "snap" and hes immediately next to the player or in my case enemy

This i believe is just something either to do with the actual movement that i currently have or the time.delta time , but I'm not entirely sure.

This is the code if you want to see it

 function Update () 
 {
     var controller : CharacterController = GetComponent(CharacterController);
     // gets the character controller and contains it information inside variable                                named controller
  
     // Rotate around y - axis
     transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
     
     // Move forward / backward
     var forward : Vector3 = transform.TransformDirection(Vector3.forward);
     var curSpeed : float = speed * Input.GetAxis ("Vertical");
     
     controller.SimpleMove(forward * curSpeed);
     
     
        if(controller.isGrounded) // if the character controller is colliding with anything that is 
        // collidiable 
        {
            controller.height = standardHeight ;
            controller.center.y=0.05; // repositions the character controller to 0.05 on the y axis
            
            
          
         if (Input.GetButton("Jump")) // If the jump button is held down 
         {  
             moveDirection.y= jumpSpeed;
             controller.height = jumpHeight;
             controller.center.y=0.06;
            
            
            
         }
         
         }
         
         if(Input.GetButtonUp("Jump")) // If jump button has been pressed and released
            
         {  
             
            
            controller.height = middleHeight;
          
            controller.center.y =0.04;
            
            
               
         }
         
       
         
        
         
         
         if( jumpSpeed==70.0 && !controller.isGrounded )// if the jump speed if 70.0 and its not 
         // colliding with anything or not on the ground
         
          {
               if(Input.GetButtonUp("Fire2") && gravity ==90.0)// if button has been pressed and released
               // and gravity at this point is 90.0 then do below
               {
                   
                   var step = bouncespeed * extraspeed* Time.smoothDeltaTime;
                   gravity =0;
     
     // Move our position a step closer to the target.
                   transform.position = Vector3.MoveTowards(transform.position,
                   target.position, step);
                   animation.CrossFade("Bounce");
                    }
                     
                     }
                     
                     if(gravity ==0)
                     {
                       gravity =90.0;
                     }
                     
                  
                    
              
              
          
         
           
          
       
           
               
               
               
         
        
        
        
         
    
     
     
     
     controller.Move(moveDirection * Time.deltaTime);
     moveDirection.y -= gravity * Time.deltaTime;
 }
 
Comment

People who like this

0 Show 2
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 Fattie · Mar 27, 2013 at 10:42 AM 0
Share

cick Edit, format first batch of code

it's almost certain you are going to have to dramatically simplify your question and make it more specific if you wanna get an answer

avatar image Charles_Gams · Mar 27, 2013 at 11:30 AM 0
Share

Thanks i did just that hope it helps identify my code better

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

How to move an object a specific speed in km/h? 2 Answers

How to limit the force from player input without limiting speed 2 Answers

Acceleration with CC 0 Answers

My Character is moving fine horizontally and vertically, but moves way too fast diagonally 2 Answers

Moving up and down (in a slope) without change to velocity or "bumping" 0 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