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 /
avatar image
0
Question by WbrJr · Dec 05, 2017 at 07:09 PM · movementrigidbodyvelocityspeedbullet

Rigidbody speed in some senes different?!

Hello out there, the Controller of a Enemy-bullet is speeding the bullet up:

 void Update ()
     {
         rb.velocity = transform.forward * speed;
     }

In some scenes, the bullet travels at the correct speed, in others it is very very slow, but still a bit moving.

here the complete script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class EnemyBullet : MonoBehaviour {
 
     [HideInInspector]
     public float speed;
     [HideInInspector]
     public float makePlayerSlower;
     [HideInInspector]
     public float lifeTime;
     [HideInInspector]
     public ParticleSystem explosion;
 
     float lifeTimer;
     GameObject player;
     Rigidbody rb;
     bool mayDestroy = true;
     bool wasStuck;
 
     // Use this for initialization
     void Start ()
     {
         rb = GetComponent<Rigidbody>();
     }
     
     // Update is called once per frame
     void Update ()
     {
         rb.velocity = transform.forward * speed;
         wasStuck = false;
 
         lifeTimer += Time.deltaTime;
         if ((lifeTimer >= lifeTime) && mayDestroy)
             Destroy(gameObject);
     }
 
     void OnTriggerEnter(Collider other)
     {
         if(other.CompareTag("Player"))
         {
             transform.parent = other.transform;
             rb.isKinematic = true;
             player = other.gameObject;
             player.GetComponent<PlayerControl>().speedReduction = makePlayerSlower;
             player.GetComponent<PlayerControl>().AddStickyBall(gameObject);
             GetComponent<Collider>().enabled = false;
             mayDestroy = false;
             wasStuck = true;
         }
         else if(!other.CompareTag("Enemy"))
         {
             Destroy(gameObject);
         }
     }
 
     void OnDestroy()
     {
         ParticleSystem explosionClone = Instantiate(explosion, transform.position, transform.rotation);
         Destroy(explosionClone, 1f);
         if(wasStuck)
             player.GetComponent<PlayerControl>().RemoveStickyBall();
     }
 }
 

I am pretty shure, that i don't change the transform of the bullet in any other scripts! And i have now Idea...

(btw: if you have any advice for my in my way of scripting, please let me know! :D)

Thanks for reading and trying to help! WbrJr

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by admiralnoobdog · Dec 05, 2017 at 08:06 PM

Try using Time.deltaTime

 void Update ()
      {
          rb.velocity = transform.forward * speed*Time.deltaTime;
      }
 
 and try using FixedUpdate() instead of Update() when you are trying to move objects using RigidBody

`

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 WbrJr · Dec 05, 2017 at 08:07 PM 0
Share

Ok, wow...I am Pretty stupid. I never really payed attantion to it, but Thanks alot!! :D

avatar image WbrJr · Dec 05, 2017 at 08:11 PM 0
Share

First time running the game with the change, it worked. But after tweaking and trying a secound time, it was as slow as always... any idea? :/ thanks

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

126 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 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

Comparing rigidbody speeds 1 Answer

rigidbody It's going up and bounces when is moving 1 Answer

Add velocity relative to ground? 1 Answer

Player movement not working with unity 5 1 Answer

Mimic Gravity Movement Via Setting Velocity 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