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 awplays49 · Dec 21, 2014 at 10:08 AM · answers

Code debugging message but not fulfilling action commanded to do

Where it says "here". it actually prints it, meaning the condition is met, but the velocity is not changed. why?

         // Jump controls
         Debug.Log (rigidbody.velocity);
         if (Input.GetKey (KeyCode.Space) && Jumping == false && transform.position.y - transform.lossyScale.y / 2 < Terrain.activeTerrain.SampleHeight (transform.position) + 1)
         {
             Jumping = true;
         }
         if (transform.position.y - transform.lossyScale.y / 2 >= Terrain.activeTerrain.SampleHeight (transform.position) + JumpHeight * 10)
         {
             Jumping = false;
         }
         if (Jumping == true)
         {
             rigidbody.velocity = new Vector3 (0, (JumpSpeed / ((Terrain.activeTerrain.SampleHeight (transform.position)) + JumpHeight * 10 - transform.position.y - transform.lossyScale.y / 2) * 16), 0);
         }
         if (Jumping == false)
         {
             if (transform.position.y - transform.lossyScale.y / 2 > Terrain.activeTerrain.SampleHeight (transform.position) + 1)
             {
                 Debug.Log ("Here");
                 rigidbody.velocity = new Vector3 (0, -(JumpSpeed / ((Terrain.activeTerrain.SampleHeight (transform.position)) + JumpHeight * 10 - transform.position.y - transform.lossyScale.y / 2) * 16), 0);
             } else {
                 rigidbody.velocity = new Vector3 (0, 0, 0);
             }
         }
Comment
Add comment · Show 3
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 awplays49 · Dec 21, 2014 at 08:22 AM 0
Share

Update:when the player gets to Terrain.activeTerrain.SampleHeight (transform.position) + JumpHeight * 10 he just lunges up and then goes a bit slower than before.

avatar image awplays49 · Dec 21, 2014 at 03:27 PM 0
Share

What should i be looking for? @bubzy

avatar image meat5000 ♦ · Dec 21, 2014 at 03:43 PM 0
Share

Put your debug in the codeblock after the velocity change under 'Here'.

 Debug.Log ("Here");
 rigidbody.velocity = new Vector3~/~
 Debug.Log (rigidbody.velocity);

Do you really need the 'new' keyword when adjusting the velocity? This I don't know.

Edit: Docs say it is :)

1 Reply

· Add your reply
  • Sort: 
avatar image
-1

Answer by awplays49 · Dec 21, 2014 at 04:40 PM

i dont but i like keeping consistent in the pattern of my coding, ocd :{

I have it working now, but when he falls he sometimes shoots through the floor and snaps back up. heres my code

     if (Input.GetKey (KeyCode.Space) && PlayerFoot < TerrainHeight + 1) 
         {
             Jumping = true;
         }
         if (Jumping == true)
         {
             if (PlayerFoot < TerrainHeight + JumpHeight * 10 - 1)
             {
                 PlayerFootSet = PlayerFoot;
                 if (PlayerFoot < (TerrainHeight + JumpHeight * 10) / 4 * 3)
                 {
                     rigidbody.velocity = new Vector3 (0, (JumpSpeed / (TerrainHeight + JumpHeight * 10 - PlayerFoot)) * 32, 0);
                 } else {
                     rigidbody.velocity = new Vector3 (0, (JumpSpeed / (TerrainHeight + JumpHeight * 10 - PlayerFoot)) * 24, 0);
                 }
             } else {
                 Jumping = false;
             }
         }
         if (Input.GetKeyUp (KeyCode.Space))
         {
             Jumping = false;
         }
         if (Jumping == false && PlayerFoot > TerrainHeight + 1)
         {
             if (PlayerFoot < (TerrainHeight + JumpHeight * 10) / 4 * 3)
             {
                 rigidbody.velocity  = new Vector3 (0, -(JumpSpeed / (TerrainHeight + JumpHeight * 10 - PlayerFootSet)) * 32, 0);
             } else {
                 rigidbody.velocity = new Vector3 (0, -(JumpSpeed / (TerrainHeight + JumpHeight * 10 - PlayerFootSet)) * 24, 0);
             }
         }
         if (Jumping == false && PlayerFoot <= TerrainHeight + 1)
         {
             rigidbody.velocity = new Vector3 (0, 0, 0);
         }


What what happening is he was going slightly over the jump height because i used if

Comment
Add comment · Show 10 · 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 awplays49 · Dec 21, 2014 at 05:35 PM 0
Share

Its still happening? @meat5000 i changed something and it just went back to what it was doing before

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : $$anonymous$$onoBehaviour {
 
     public float Speed;
     public float JumpHeight;
     public float JumpSpeed;
     public bool Jumping;
     public float PlayerFoot;
     public float PlayerFootSet;
     public float TerrainHeight;
     public float TerrainHeightSet;
 
     public float Sensitivity;
     private float $$anonymous$$ouseXSet;
 
     void Start () {
         $$anonymous$$ouseXSet = 0;
         Jumping = false;
     }
 
     void Update () {
         PlayerFoot = transform.position.y - transform.lossyScale.y / 2;
         TerrainHeight = Terrain.activeTerrain.SampleHeight (transform.position);
 
         // Translation controls
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.W))
         {
             transform.position += transform.forward * Speed * Time.deltaTime;
         }
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.S))
         {
             transform.position -= transform.forward * Speed * Time.deltaTime;
         }
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.D))
         {
             transform.position += transform.right * Speed * Time.deltaTime;
         }
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.A))
         {
             transform.position -= transform.right * Speed * Time.deltaTime;
         }
 
         // Rotation controls
         if (Input.mousePosition.x > $$anonymous$$ouseXSet)
         {
             transform.Rotate (new Vector3 (0, 1, 0) * (Input.mousePosition.x - $$anonymous$$ouseXSet) * Sensitivity * Time.deltaTime);
             $$anonymous$$ouseXSet = Input.mousePosition.x;
         }
         if (Input.mousePosition.x < $$anonymous$$ouseXSet)
         {
             transform.Rotate (new Vector3 (0, -1, 0) * (-(Input.mousePosition.x - $$anonymous$$ouseXSet)) * Sensitivity * Time.deltaTime);
             $$anonymous$$ouseXSet = Input.mousePosition.x;
         }
 
         // Jump controls
         if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.Space) && PlayerFoot < TerrainHeight + 1) 
         {
             Jumping = true;
             TerrainHeightSet = TerrainHeight;
         }
         if (Jumping == true)
         {
             if (PlayerFoot < TerrainHeightSet + JumpHeight * 10)
             {
                 PlayerFootSet = PlayerFoot;
                 rigidbody.velocity = new Vector3 (0, (JumpSpeed / (TerrainHeightSet + JumpHeight * 10 - PlayerFoot)) * 32, 0);
             } else {
                 Jumping = false;
             }
         }
         if (Input.Get$$anonymous$$eyUp ($$anonymous$$eyCode.Space))
         {
             Jumping = false;
         }
         if (Jumping == false && PlayerFoot > TerrainHeightSet + 1)
         {
             if (PlayerFoot < TerrainHeight + JumpHeight * 10 - 5)
             {
                 rigidbody.velocity  = new Vector3 (0, -(JumpSpeed / (TerrainHeightSet + JumpHeight * 10 - PlayerFootSet)) * 32, 0);
             }
         }
 
         // $$anonymous$$eep player upright
         if (PlayerFoot < TerrainHeight)
         {
             transform.position += Vector3.up * 5 * Time.deltaTime;
         }
     }
 } 
avatar image meat5000 ♦ · Dec 21, 2014 at 05:51 PM 0
Share
 Debug.log(Terrain.activeTerrain.SampleHeight(transform.position).ToString());

This may not be doing what you think it is.

avatar image awplays49 · Dec 21, 2014 at 05:53 PM 0
Share

I found out this condition

   if (PlayerFoot < TerrainHeight + JumpHeight * 10 - 5)

if never met. the one it is inside, however, is. so now i know what the problem is but im not sure how to approach it. @meat5000

avatar image meat5000 ♦ · Dec 21, 2014 at 05:56 PM 0
Share

Change the condition to something more appropriate :)

avatar image awplays49 · Dec 21, 2014 at 05:57 PM 0
Share

it should be met though, im not sure why it isn't. @meat5000

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity Answers or Unity Forum? 1 Answer

Basketball Script Problem 2 Answers

[meta] Why was my question deleted and where is it now? 2 Answers

How can I get help using Unity Answers? 1 Answer

I have not received replies to my questions in here since July of 2015 - Is that typical? 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