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 poewang · Jan 20, 2016 at 03:36 PM · vector3variablevelocity

How can I change vector speed?

Sorry for my English Firstly this is a cube script and it is Instantiate randomly location. cube must go randomly.if it is collide another cube or wall ,it must change its speed and direction. I did this script and it can go randomly direction but it doesnot change speed and sometimes it stop when it collide the wall.I work 2 days on this 2 problems.Please help me ! NOT:I use 5.3.1p1. Wall and cube has box collider.Thank you for your answer. using UnityEngine; using System.Collections; using UnityEngine.UI;

public class CanScript : MonoBehaviour {

 public Rigidbody rb;
 public Vector3 git;
 public float speed=5f;

 void Awake()
 {
     rb = GetComponent<Rigidbody>();
 }

 void Start()
 {
     git.x = Random.Range(-40, 40);
     git.y = 0f;
     git.z = Random.Range(-40, 40);
 }

  void FixedUpdate()
  {
      rb.velocity = new Vector3(git.x, 0, git.z);  // i cant change speed.i want to use it
  }

 void OnCollisionEnter (Collision col)     // 
 {
     if (col.gameObject.tag == "objetag")
     {
         speed = Random.Range(5, 40);   // i want to use this speed
         git.x = Random.Range(-40, 40);
         git.y = 0f;
         git.z = Random.Range(-40, 40);
     }
 }

}

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 hexagonius · Jan 20, 2016 at 09:52 PM

 rb.velocity = git * speed;
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 poewang · Jan 21, 2016 at 11:24 AM 0
Share
  rb.velocity = git * speed;

this does not 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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can't access the velocity of a rigidbody: 'Rigidbody' does not contain a definition for 'velocity' 1 Answer

How would I counteract the force of the velocity and set it to zero after the input has stopped? 3 Answers

Need help for my Arkanoid-like game. i got problem to make my ball reflects on the wall 1 Answer

Incorrect velocity after collision 1 Answer

Assign Transform Variable With A Vector? 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