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 $$anonymous$$ · Mar 13, 2014 at 12:13 AM · gameobjecttransformmovingforwardfunction update

Moving game objects

Hi guys, first big sorry for my bad english, im working on it ;)

I want to ask you something. I want to move some objects in my game, its simple, there are asteroids which move from up to down (create up and destroy down). But they speed is static, for example 5, so if for example I catch box for speed I want to rise this speed from 5 to example 20 and after some time its will be again 5.

My code for speed is:

static var asteroidspeed : float = -5;

function Update () { rigidbody.velocity = transform.forward * asteroidspeed; }

and there is code for their creation:

var spawnPosition : Vector3 = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z); var spawnRotation : Quaternion = Quaternion.identity; Instantiate (hazard, spawnPosition, spawnRotation);

but the problem is, when I change speed from Start() to Update() because if there is Start() asteroids which are already exist dont react on changing speed but asteroids which will be create react on it so I changed it on Update(), but asteroids are acting weird. They rotate around their axis and they dont move from up to down directly but they create something like circle or I dont know :D Simple it looks very strange

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

2 Replies

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

Answer by Andres-Fernandez · Mar 13, 2014 at 07:55 AM

If your asteroids have a rigidbody component, don't use the transform component to move them. Use forces to move them instead (like the AddForce function). If you still want to move them using the transform component, make sure they are marked as isKinematic (otherwise they will not move).

If you want to move them, try using the RigidBody.MovePosition function. I believe that's what you are looking for.

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 $$anonymous$$ · Mar 13, 2014 at 01:39 PM 1
Share

thanks man :) it works :) I used Addforce function :) thanks everybody :)

avatar image
0

Answer by KrisSchnee · Mar 13, 2014 at 04:15 AM

I'm new at this too, but it looks like part of the problem is in your Update function. I think Update is called at every animation frame, so the effect of this function is being applied at unpredictable times. Try changing this:

 function Update () { rigidbody.velocity = transform.forward * asteroidspeed; }

to this:

 function Update () { rigidbody.velocity = transform.forward * asteroidspeed * Time.deltaTime; }

Doing that will multiply the effect of your speed by some number > 0 and < 1 (eg. .005) to reflect that it's happening once per frame.

I'm less sure about this, but think you should not be using "static" and that you should set the value of asteroidspeed in the Start() function, not in the declaration above it.

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 $$anonymous$$ · Mar 13, 2014 at 07:14 AM 0
Share

i tried it but they dont create circle :D little win ;) but problem is that they stay on the same place and rotate on their axis, I tried to increase speed but its doesnt work :/

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

21 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

Related Questions

change the front point or head of a GameObject 1 Answer

Truck moves sideways when using transform.forward 1 Answer

Adding a prefab to gameObject at a certain position in runtime 0 Answers

Creating new Transform from existing objects Transform to Instantiate object 1 Answer

Animation issue (OnTriggerEnter) ***SOLVED*** 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