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 TheHardkaare · Apr 30, 2014 at 09:56 PM · disappearingasteroid

Asteroid disappears for no reason

For my space shooter game I need to make some asteroids move towards the player.

I've created the asteroid, made it rotate and destroy on impact.

But when I add my movement script for it, it simply just disappears when testing the game.

This is my movement script:

 using UnityEngine;
 using System.Collections;
 
 public class Mover : MonoBehaviour 
 {
     public float speed; //public float tilføjes så værdien kan ændres i selve unity istedet for at være kodebaseret
     void Start ()
     {
         rigidbody.velocity = transform.forward * speed; //transform forward er bevægelsen langt z-aksen.
     }
 }

Ignore the danish notes, please.

Comment
Add comment · Show 1
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 ForeignGod · Apr 30, 2014 at 10:31 PM 0
Share

im not familiar with C# but shouldnt you state what "speed" is? so far i only see that you use your float speed in your velocity but i cant see how much that speed is?

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by wibble82 · Apr 30, 2014 at 11:03 PM

I suspect it's just going off screen, unless some other code is killing it. Best bet - pause the game as soon as it runs, find the object in the scene view and see where it's gone!

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 TheHardkaare · May 01, 2014 at 01:18 PM 0
Share

I found the problem.

It's moving along the z axis, which in my case, is the blue vector in this picture: http://i.imgur.com/hb9DtNw.png

I want to move it along the green vector, but how can I achieve this?

Do I replace the transform.forward with something similar?

avatar image wibble82 · May 01, 2014 at 03:53 PM 0
Share

yup - that or rotate your object. transform.forward will push it along its own z axis. transform.right will push it along its own x axis. transform.up will push it along its own y axis. Or if you want to work in world space (i.e. ignore the orientation of the object), there's Vector3.up, Vector3.right and Vector3.forwards.

avatar image
0

Answer by KevLoughrey · Apr 30, 2014 at 10:29 PM

It might be moving off camera when Start() is called? Try logging its position to the console to see what's happening with it, or reducing the speed.

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 TheHardkaare · May 01, 2014 at 01:22 PM 0
Share

I found the problem.

It's moving along the z axis, which in my case, is the blue vector in this picture: http://i.imgur.com/hb9DtNw.png

I want to move it along the green vector, but how can I achieve this?

Do I replace the transform.forward with something similar?

avatar image KevLoughrey · May 01, 2014 at 02:17 PM 0
Share

transform.up should work, I think.

avatar image
0

Answer by giantkilleroverunity3d · May 01, 2014 at 07:48 PM

Speed or wrong direction is what I have found to be the first questions to ask oneself since this is a dynamic graphics environment. From 'One who has lost many in play...'

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

26 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

Related Questions

Script to change colour makes GUItext invisible. Any idea why? 3 Answers

cannot show my hazard in space shooter 0 Answers

SphereCollider on lfoot is not recognized 0 Answers

Asteroid wrapping effect. 1 Answer

Why are all the particles in my particle system disappearing when it's off screen? 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