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 /
This question was closed May 11, 2018 at 01:11 PM by polan31 for the following reason:

Other

avatar image
0
Question by polan31 · May 09, 2018 at 02:14 PM · clickaddpointssubstract

Can you determine the speed of falling?

Could anyone help change my script?

I have an object "Ball".

My object is a ball and it bounces up.

Every time when I press the left mouse button, "Ball" jumps up.

Each up move adds points.

Now my question.

When the object falls, the points decrease, but the speed of free fall continues to grow.

This causes points to not keep up with the falling ball.

The result is that when the ball stop to the ground, instead of having 0 points it has, for example, 66.

Can you determine the speed of falling?

How do that?

For now, I just add to my object:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Score : MonoBehaviour {
 
     public Text scoreText;
 
     [SerializeField]
     int score = 0;
 
     [SerializeField]
     Vector3 _lastPosition;
 
     // Use this for initialization
     void Start () {
         _lastPosition = this.transform.position;
     }
 
     // Update is called once per frame
     void Update () {
         if( this.transform.position.y > _lastPosition.y  )
             score++;
         else{
             score--;
         }
 
 
         _lastPosition = this.transform.position;
     
         scoreText.text = "Score" + score;
 
     }
 }
 
 
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

3 Replies

  • Sort: 
avatar image
0

Answer by anthot4 · May 09, 2018 at 02:24 PM

You could check the velocity of the rigidbody as soon as the ball jumps. Have two if statements one to check for positive velocity and if it is add to the score and if it is negative subtract from the score. Have this inside your if statement which check for left mouse button down on line 20.

Comment
Add comment · Show 2 · 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 polan31 · May 09, 2018 at 02:32 PM 0
Share

If I can be honest, I will know how to do it with the condition of adding points, but with subtraction I will not know how to do it.

avatar image anthot4 polan31 · May 09, 2018 at 02:48 PM 0
Share

Something like this:

Vector3 LastPosition = Vector3.zero;

Void FixedUpdate(){

speed = (transform.position - LastPosition).magnitute; LastPosition = transform.position;

if (Input.Get$$anonymous$$ouseButtonDown(0){

if (speed >=0){ Score++; }

if (speed < 0){ Score--; } }

}

avatar image
0

Answer by polan31 · May 09, 2018 at 02:48 PM

Can not somehow be addicted to the height Y?

For example, as the height grows and the points grow, as the height fall and the points fall.

Comment
Add comment · Show 2 · 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 anthot4 · May 09, 2018 at 02:52 PM 0
Share

You could do that it would be something like this:

score += transform.y; // this would add the transform point on y to your score.

If your doing it that way it would be best to put the code above in a coroutine then add it to the players score every second or so.

avatar image polan31 anthot4 · May 09, 2018 at 03:11 PM 0
Share

Ok, I found something like this on unity servers and works in my 2d application.

https://answers.unity.com/questions/613277/how-to-increase-score-with-y-axis.html

However, I still can not transform it in such a way that the points are going down.

avatar image
0

Answer by Guy_Yome · May 10, 2018 at 07:55 PM

Okay I have a solution. I assume that your ball will be jumping on platforms that are maybe generated on the "fly". So you'll have to make a list of platforms where you will add all the new platforms you create at the end of the list. You could use the collision detection built in Unity to help you detect what you are doing. Whenever you land on a new and higher platform, you will have to remove the first element in the list (which is the platform below). Doing so, the only platforms in the list will be the platform you are on and the platforms that are above you (Shown in blue).


Whenever you fall and collide with a platform that is not in the list (Shown in red), it will mean that it was a platform below and you will make the player lose points. Whenever you land on the first element of the list, you landed on your own platform and gained nothing. And for the rest (above), you will gain points. One other case is if you fall in the void (not on a platform), you could use a height that is an arbitrary distance lower than the actual platform (red line in the drawing) to see if the ball is lower than that. If it is, lose points and respawn the ball on the last platform. I hope this helps.


The blue platforms shown are the ones still in the ist. The red ones are not in the list anymore. The arrows say what actions you did to reach this position. down = fall, up = jump The red line is the point of falling in the void. The green circle is your ball.

alt text


unit-help.png (3.1 kB)
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

Follow this Question

Answers Answers and Comments

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

Related Questions

Adding and Substracting ammunition 1 Answer

weird result when substracting/adding; 1 Answer

JavaScript: Sound & Points deduct On click Help! 0 Answers

Problem with reducing points 1 Answer

Trigger animation OnMouseDown 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