Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by dandelo99 · Jan 13, 2016 at 07:16 PM · fpsconstantforceswimming

What can i use an alternative to constantForce for swimming basicly

I have a swimming script (it is really basic) but i cant use constantForce which added my script for swimming. Because of some reasons i couldn't add rigid body to my FPCharacter. Now i want to rise my character in the water with pressing "Space Key" when stop pressing, it will fall again. This is the script;(constantForce convert to comment line)

 #pragma strict
 var waterLevel : float;
 private var isUnderwater : boolean;
 private var normalColor : Color;
 private var underwaterColor : Color;
 private var ChMotor : FPSWalkerEnhanced;
 private var canSwim = false;
 private var underGround = false;
 var groundLevel : float;
 
 function Start () 
 {
     normalColor = new Color (0.5f, 0.5f, 0.5f);
     underwaterColor = new Color (0.22f, 0.65f, 0.77f, 0.5f);
     ChMotor = GetComponent(FPSWalkerEnhanced);
 }
 
 function Update () 
 {
     if ((transform.position.y < waterLevel) != isUnderwater)
     {
         isUnderwater = transform.position.y < waterLevel;
         if (isUnderwater) SetUnderwater ();
         if(!isUnderwater) SetNormal ();
     }
     
     if(transform.position.y < groundLevel)
     {
         canSwim = false;
         underGround = true;
     }
     else
     {
         underGround = false;
     }
     
 /*     if (isUnderwater && Input.GetKey(KeyCode.E))
     {
         constantForce.relativeForce = Vector3(0, 0, 1);
     }
     else 
     {
         constantForce.relativeForce = Vector3(0, 0, 1);
     }
     
     if (isUnderwater && Input.GetKey(KeyCode.Q))
     {
         constantForce.relativeForce = Vector3(0, 0, 1);
     } */
 }
 
 function SetNormal ()
 {
     canSwim = false;
     RenderSettings.fogColor = normalColor;
     RenderSettings.fogDensity = 0;
     ChMotor.gravity=20;
     ChMotor.walkSpeed=7;
     ChMotor.runSpeed=11;    
 }
 
 function SetUnderwater ()
 {
     RenderSettings.fogColor = underwaterColor;
     RenderSettings.fogDensity = 0.05f;
     ChMotor.gravity=2;
     ChMotor.walkSpeed=2;
     ChMotor.runSpeed=7;    
 }
Comment
Add comment · Show 1
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 dandelo99 · Jan 14, 2016 at 01:49 PM 0
Share

I am using FPWalkerEnhanced.js which doesn't need rigidbody.

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

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

Related Questions

Limit vertical rotation of Camera 5 Answers

Aim Down Sights Script Unable to Work 0 Answers

Camera not moving with car- How Can I change parent object while playing? 1 Answer

Gfx.WaitForPresent rant, and editor fix 0 Answers

How do i fix a multiplayer fps health issue? 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