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 mcarthur03 · Jan 29, 2015 at 08:23 PM · rigidbodytimejumpsecond

my jump every 3 seconds program is not working

my jump every 3 seconds program is not working, I am new to unity and I suspect I have done something wrong and have come here to ask. the code behind it is in csharp. I am attempting to make a sphere with rigidbody jump but it just continues counting down past the point it was meant to jump and dosent reset either.

using UnityEngine; using System.Collections;

public class bounceeach3seconds : MonoBehaviour {

 public float jumpheight = 500;
 public float timer;
 
 // Use this for initialization
 void Start () 
 {
     timer = 3;
     
 }
 
 // Update is called once per frame
 void Update () 
 {
             timer -= Time.deltaTime;

                 if (timer <= 0){
                     rigidbody.AddForce(0, jumpheight, 0);
                     timer = 3;
             }
 }

}

Comment
Add comment · Show 4
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 meat5000 ♦ · Jan 29, 2015 at 08:18 PM 0
Share

Ok it might not make a difference, if it's throwing no errors, but try this anyway.

You are comparing your floats to ints. In my past experience this has been ok but I'm not sure about C#. When using a value to be a float, place a decimal and f suffix.

timer = 3.0f;

Humour me and start there.

avatar image Mmmpies · Jan 29, 2015 at 08:33 PM 0
Share

No that code is fine. The issue has to be somewhere else. I just put a cube in a scene and added your script to the cube with a rigidbody added to it and it's fine with that.

avatar image meat5000 ♦ · Jan 29, 2015 at 08:40 PM 0
Share

Yeah, I was really clutching at straws with that one :P

avatar image Mmmpies · Jan 29, 2015 at 08:52 PM 0
Share

Almost 17k karma, I think we can let you off this one, you want to see me trying my hand at JS! Just painful.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Chris_Dlala · Jan 29, 2015 at 08:34 PM

Hi, I can't see anything immediately wrong. Do you receive any errors in the console window? The call to rigidbody looks on the same gameobject as this script, is there a rigidbody on the same gameobject? All I can think of is that the rigidbody is null and therefore throwing an error, causing the update to end, never getting the the line after where you set the timer to 3.

Try adding a RigidBody reference as a member variable and assigning it in the editor. Or, add Debug.Log call at certain points to see how far/what lines get called.

I hope that helps =D

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 Shudrum · Jan 29, 2015 at 08:35 PM

Hi !

I have just copy/past your script and it works perfectly, only if the object with the rigidbody was on ground, else the falling velocity is too fast to work.

As your are new in Unity, sorry but stupid questions :

  • 1 : Have you tried with a plane below your object ?

  • 2 : For the (1) : do your object have a collider ?

  • 3 : Did your script correctly attached to your object ?

Comment
Add comment · Show 1 · 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 Mmmpies · Jan 29, 2015 at 08:50 PM 0
Share

And whilst we're on the subject of rigid-bodies what's the mass set to, if more than around 10 you'll probably not even notice it jump. The mass on my test cube was just set to 1.

avatar image
0

Answer by georgepear1 · Apr 14, 2020 at 09:28 AM

Working! Thanks dude.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody jump adds bounce energy to second jump 1 Answer

How to get global up vector? 1 Answer

Rigidbody.MovePosition doesn't move reliably? 1 Answer

Jump without character controller?? 2 Answers

How do I stop an object from jumping VERY high at first? 1 Answer


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