NotNa19 Posted August 9, 2021 Share Posted August 9, 2021 (edited) Perhaps this is a too simple question, but I have been sitting with this for a long time. The task is simple - I need to create a number of identical objects that move in a random direction. I use primitive boxes and add to them a property (c++ code) that generates a move in a random direction. But when launched, they all move in the same direction. Moreover, when restarting, the direction changes, but as before it is the same for everyone. Perhaps I am missing something, but I did not find a solution to this problem in the documentation. Edited August 10, 2021 by NotNa19 Link to comment
silent Posted August 10, 2021 Share Posted August 10, 2021 NotNa19 Maybe you can show us your code and some videos to demonstrate what's going on? It would be much easier to understand the root cause. Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
NotNa19 Posted August 10, 2021 Author Share Posted August 10, 2021 I have a property where a random direction of movement is set: Spoiler #include "BoxMove.h" #include <ctime> using namespace Unigine; using namespace Math; REGISTER_COMPONENT(BoxMove); void BoxMove::init() { } void BoxMove::update() { Unigine::Math::Random rd; vec3 dir; dir = vec3(rd.getInt(-1, 2), rd.getInt(-1, 2), 0); vec3 p0 = node->getWorldPosition(); vec3 p1 = p0 + dir * speed * Game::getIFps(); node->setWorldPosition(p1); } And I have three boxes with this property: Spoiler I want the boxes to move in a random direction, but each box has a different direction. But they all move in the same, although a random direction: Spoiler Boxes.mp4 Link to comment
silent Posted August 10, 2021 Share Posted August 10, 2021 Will be there any difference if you will use Game::getRandomInt() instead of Math::Random? If that will not work, try to set different seeds each time via Game::setSeed(). I suppose that for Math::Random you need also specify different seeds each time via setSeed() method. Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
NotNa19 Posted August 10, 2021 Author Share Posted August 10, 2021 Thanks for the answer! The first way really helped me. 1 Link to comment
Recommended Posts