• 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 liero116 · Jan 21, 2013 at 12:38 PM · fps

FPS Character controller special jump

So Im trying to make this special kind of jump in my first person game. Basically, you press this special jump (boost) button and you fly forward in your player's Z direction. I already have this part working just fine. The actual issue that I'm having is by looking in a different direction with the mouse, your forward momentum is changed to whatever direction you're facing. What I want to happen is for you to activate the boost, you'll fly forward in whatever direction you were facing when you activated it and you'll continue to fly in that direction regardless of what direction you choose to look in afterwards.

I'm pretty much stuck on this one. Any ideas?

Comment
Add comment · 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 AlucardJay · Jan 21, 2013 at 02:28 PM 1
Share

I did something similar to what you need in this answer for sliding : http://answers.unity3d.com/questions/368509/how-to-do-sliding-like-crysis-andor-farcry.html

Basically when the input for sliding is pressed, start a timer and store a reference to the current velocity (direction of travel), then while that timer is running override input commands to the character motor and feed it that stored velocity. So when you look around while the timer is running, the movement will be in the same direction as when the slide (special jump in your case).

here is the part of the script I think you will find useful :

 #pragma strict
 
 private var ch$$anonymous$$otor: Character$$anonymous$$otor;
 private var tr: Transform;
 
 public var slideSpeed: float = 20; // slide speed
 private var isSliding : boolean = false;
 private var slideForward : Vector3; // direction of slide
 private var slideTimer : float = 0.0;
 public var slideTimer$$anonymous$$ax : float = 2.5; // time while sliding
 
 function Start()
 {
     ch$$anonymous$$otor = GetComponent(Character$$anonymous$$otor);
     tr = transform;
 }
 
 function Update()
 {
     // - slide -   
     if (Input.Get$$anonymous$$eyDown("f") && !isSliding) // press F to slide
     {
        slideTimer = 0.0; // start timer
        isSliding = true;
        slideForward = tr.forward; // store a reference to the current direction of travel
     }
     
     if (isSliding)
     {
        ch$$anonymous$$otor.movement.maxForwardSpeed = slideSpeed; // set max speed as slide speed
        ch$$anonymous$$otor.movement.velocity = slideForward * speed; // fix the direction of travel to the same as the start of the slide
 
        slideTimer += Time.deltaTime;
        if (slideTimer > slideTimer$$anonymous$$ax)
        {
          isSliding = false;
        }
     } 
 }
avatar image liero116 · Jan 22, 2013 at 12:41 PM 0
Share

After some testing and retooling this is close enough to what Im trying to do that Im about 99% sure that this will work for me.

Thanks!

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

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

Is there a way to create applications that run on fixed frame rate of 60fps on iOS? 1 Answer

Performance issue loading resource 1 Answer

FPS Animation with particles 0 Answers

Import Componet ( Variable ) Error Unexpected Token 3 Answers

FPS Animations for head and arms 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