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 AbominationGames · Feb 04, 2017 at 09:50 AM · c#timeprojectilefireballwizard

Fireball not moving after time change

Okay so I'm working on a wizard game and I was doing great today up until I noticed a bug when I went to try to record a bit of progress. I'm spawning a fireball and it works great when I'm running around and just shooting fireballs. I can use my teleport ability with no problems and still continue to fire the projectiles. The problem I'm running into is, once I use my slow motion/slow time ability and I come back to full speed and go to shoot. The fireball just dies off and falls limp, it doesn't look like it's adding any kind of force after I come back to normal speed. I'm not great with the who time stuff so I'm not sure what is making it all happen this way. Was hoping someone else might have an idea or has ran into a similar problem.

I will include the scripts for where the spell should spawn, the fireball and the slow motion so that you can try to replicate the problem or see if you can figure out what's wrong with it just from the code. I've also uploaded a build of the game to DropBox, I will post the link here and you can test it out and see what I am talking about.

Playable DropBox Download:

https://www.dropbox.com/s/4h74cl3g1hs5dk6/Build.zip?dl=0

Keys: WASD T = Teleport G = Slow Time F = Gravity Off v = Gravity On

CODE - Fireball using UnityEngine; using System.Collections;

 public class Fireball : MonoBehaviour {
 
     [SerializeField]
     private float appliedThrust = 150.0f;
     public GameObject explosionPrefab;
     private Rigidbody rb;
     private Vector3 direction;
 
     // Use this for initialization
     void Start () {
         rb = GetComponent<Rigidbody>(); //Grab our rigidbody
         direction = new Vector3(0, 2, 15); //What direction we will send our fireball, 2 up, 15 forward
         rb.AddForce(transform.TransformDirection(direction) * appliedThrust); //Apply our Thrust to our Rigidbody in our direction
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     private void OnCollisionEnter(Collision collision)
     {
         //Prevents our fireballs from hitting each other and exploding if we adjust speed back up
         if (collision.gameObject.tag != "Fireball")
         {
             Instantiate(explosionPrefab, transform.position, transform.rotation); //Instantiate an explosive prefab
             Destroy(gameObject); //Destroy this fireball
         }
     }
 }

CODE SpellSpawner

 using UnityEngine;
 using System.Collections;
 
 public class SpellSpawner : MonoBehaviour {
 
     public GameObject fireballPrefab; //We need to be able to tell our script what item to spawn in the game
     private bool canShoot; //We set a bool to let our engine know if we are able to shoot or not
 
     // Use this for initialization
     void Start () {
         //When starting the game, our character should be able to shoot
         canShoot = true;
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     public void Fireball()
     {
         //If the player is able to shoot
         if (canShoot == true)
         {
             //Start our Coroutine, we use a Coroutine so we can prevent the player from shooting rapidly
             StartCoroutine(FireballDelay());            
         }
         else
         {
             //If we can't shoot, we return to the top to try the procedure over again
             return;
         }
     }
 
     //We need a way to prevent the player from constantly spamming fireballs
     private IEnumerator FireballDelay()
     {       
         canShoot = false; //Tell our engine that the player can no longer shoot
         yield return new WaitForSeconds(1.5f); //Wait for 1.5 seconds in order to line up our animation and fireball spawn
         //This also keeps the player from firing for 1.5 seconds
         Instantiate(fireballPrefab, transform.position, transform.rotation); //Spawn a fireball
         canShoot = true; //Tell our engine that the player is able to shoot again
     }
 }

CODE - SlowMotion

using UnityEngine; using System.Collections;

public class SlowMotion : MonoBehaviour {

 [SerializeField]
 private float slowdownFactor = 0.05f;
 [SerializeField]
 private float slowdownLength = 2.0f;

 private void Start()
 {
 }
 private void Update()
 {
     Time.timeScale += (1.0f / slowdownLength) * Time.unscaledDeltaTime;
     Time.timeScale = Mathf.Clamp(Time.timeScale, 0.0f, 1.0f);
 }

 public void EnableSlowMotion()
 {
     Time.timeScale = slowdownFactor;
     Time.fixedDeltaTime = Time.timeScale * 0.02f;
 }

}

I know the canShoot isn't really used, I changed the code and just left it in so I could use it later when I go back to change things, it's not really hurting anything so I figured why bother taking it out.

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

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

7 People are following this question.

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

Related Questions

How do you fix NullReferenceException: Object reference not set to an instance of an object... errors? 1 Answer

Get Internet Year PHP 0 Answers

Adding Coyote Time and Jumpbuffer gave player infinite jumps. 1 Answer

Is there a way to calculate elapsed Time in total? (Even when the App is closed etc.) 1 Answer

My code has some invalid arguments 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