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 Mac 1 · May 15, 2011 at 04:08 AM · fpsjumpingmoving

DastardlyBanana(moving while jumping.

Hello. I know some of you may be familiar with DastardlyBanana's FPS Package. I am having some trouble with the FPSWalkerDB Script. (Well, first of all, for some reason, the standard Character Motor script wont work instead of FPSWalker, and if you know of a way to use this instead I would prefer that.) But if that can't happen, I would like to know how to change this script so that I can move around in air after while jumping (instead of just moving in one direction.) I tried messing around with the "grounded" variable, trying to remove it in some places and toying with the grounded flags. The script is below: (Mostly lines 90-128 if I am correct). sorry it is long.

private var speed = 6.0; var aimSpeed = 2.0; var sprintSpeed = 10.0; private var canSprint : boolean = true;

var sprintJumpSpeed = 8.0; var normSpeed = 6.0; var crouchSpeed = 6.0; var crouchDeltaHeight = 1.0; var jumpSpeed = 8.0; var normJumpSpeed = 8.0; var gravity = 20.0; private var mainCamera : GameObject; private var weaponCamera : GameObject; static var crouching : boolean = false; private var stopCrouching : boolean = false; private var standardCamHeight : float; private var crouchingCamHeight : float;

private var moveDirection = Vector3.zero; private var grounded : boolean = false;

static var walking : boolean = false;

function Start() { speed = normSpeed; mainCamera = gameObject.FindWithTag("MainCamera"); weaponCamera = gameObject.FindWithTag("WeaponCamera"); crouching = false; standardCamHeight = mainCamera.transform.localPosition.y; crouchingCamHeight = standardCamHeight - crouchDeltaHeight; }

function Update() { if(mainCamera.transform.localPosition.y > standardCamHeight){ mainCamera.transform.localPosition.y = standardCamHeight; } else if(mainCamera.transform.localPosition.y standardCamHeight){ weaponCamera.transform.localPosition.y = standardCamHeight; } else if(weaponCamera.transform.localPosition.y crouchingCamHeight){ if(mainCamera.transform.localPosition.y - (crouchDeltaHeight*Time.deltaTime*8) crouchingCamHeight){ if(weaponCamera.transform.localPosition.y - (crouchDeltaHeight*Time.deltaTime*8) standardCamHeight){ mainCamera.transform.localPosition.y = standardCamHeight; } else { mainCamera.transform.localPosition.y += crouchDeltaHeight*Time.deltaTime*8; } } if(weaponCamera.transform.localPosition.y standardCamHeight){ weaponCamera.transform.localPosition.y = standardCamHeight; } else { weaponCamera.transform.localPosition.y += standardCamHeight*Time.deltaTime*8; } }

 }

} function FixedUpdate() {

 if (grounded) {
     // We are grounded, so recalculate movedirection directly from axes
     moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
     moveDirection = transform.TransformDirection(moveDirection);
     moveDirection *= speed;

     if (Input.GetButton ("Jump")) {
         moveDirection.y = jumpSpeed;
         if(crouching){
             stopCrouching = true;
             normalSpeed();
         }
     }

 }

 // Apply gravity
 moveDirection.y -= gravity * Time.deltaTime;

 // Move the controller
 var controller : CharacterController = GetComponent(CharacterController);
 var flags = controller.Move(moveDirection * Time.deltaTime);    
 grounded = (flags & CollisionFlags.CollidedBelow) != 0;

 if((Mathf.Abs(moveDirection.x) > 0) && grounded || (Mathf.Abs(moveDirection.z) > 0 && grounded)){
     if(!walking){
         walking = true;
         BroadcastMessage("walking", SendMessageOptions.DontRequireReceiver);
     }
 } else if(walking){
     walking = false;
     BroadcastMessage("stopWalking", SendMessageOptions.DontRequireReceiver);
 }

}

@script RequireComponent(CharacterController)

function aiming() { speed = aimSpeed; }

function crouch() { speed = crouchSpeed; //mainCamera.transform.position.y -= crouchDeltaHeight; //weaponCamera.transform.position.y -= crouchDeltaHeight; //BroadcastMessage ("crouching", SendMessageOptions.DontRequireReceiver); this.GetComponent(CharacterController).height -= crouchDeltaHeight; this.GetComponent(CharacterController).center -= Vector3(0,crouchDeltaHeight/2, 0); crouching = true; }

function normalSpeed () { if(stopCrouching){ crouching = false; //mainCamera.transform.position.y += crouchDeltaHeight; //weaponCamera.transform.position.y += crouchDeltaHeight; this.GetComponent("CharacterController").height += crouchDeltaHeight; this.GetComponent("CharacterController").center += Vector3(0,crouchDeltaHeight/2, 0); BroadcastMessage("stopWalking", SendMessageOptions.DontRequireReceiver);

     stopCrouching = false;      
 } else if(crouching){
     speed = crouchSpeed;
     return;
 }
     speed = normSpeed;
     jumpSpeed = normJumpSpeed;

} function sprinting () { if(crouching){ crouching = false; //mainCamera.transform.position.y += crouchDeltaHeight; //weaponCamera.transform.position.y += crouchDeltaHeight; this.GetComponent(CharacterController).height += crouchDeltaHeight; this.GetComponent(CharacterController).center += Vector3(0,crouchDeltaHeight/2, 0);

 }
 if(canSprint){
     speed = sprintSpeed;
     jumpSpeed = sprintJumpSpeed;
 }

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Socrates · May 15, 2011 at 10:15 AM

I would remove the three lines of code that set up the moveDirection from if(grounded){}. You'll want to leave the jump code in that if() or find another way to limit it or you could just keep adding altitude with a jump, even while in the air. The grounded value also looks to be used in other logic checks, so removing it could cause unintended consequences.

function FixedUpdate() { // Recalculate moveDirection directly from axes moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;

 if (grounded) {
 ...

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

Answer by Mac 1 · May 15, 2011 at 04:03 PM

Okay, so I figured out how to use it with the "Character Motor". Just add the FPSInput Script too it as well. ah, I'm so stupid sometimes. Thanks to Socrates for helpful information. (But if DastardlyBanana sees this post this is something you might want to add).

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

No one has followed this question yet.

Related Questions

Player Falls Much Slower While Moving 2 Answers

Why is my Jumping script not working with my Movement script? 1 Answer

Moving through walls 4 Answers

One scipt to cover all guns 1 Answer

Fps Gliding 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