Jump to content

How to increase the speed when I move camera via keyboard


photo

Recommended Posts

I've tried to call 

Unigine::Game::get()->getPlayer().get()->setVelocity(Unigine::Math::vec3(5000.f,0.f,0.f));

but it seems not what I expected. I just want to fly qicker by using keyboard or mouse in runtime . 

Is there any solution ? thanks. 

 

Link to comment

Hello!

to increase speed of Player spectator you need to change MinVelocity for usual moving and MaxVelocity for moving with shift key

image.png

if you wand to change it in runtine - methods has the same name

Unigine::Game::get()->getPlayer()->setMinVelocity(50);
Unigine::Game::get()->getPlayer()->setMaxVelocity(100);

https://developer.unigine.com/en/docs/2.17/api/library/players/class.playerspectator?rlang=cpp&words=player%2Cplayerlll%2Cplayerll#setMinVelocity_float_void
https://developer.unigine.com/en/docs/2.17/api/library/players/class.playerspectator?rlang=cpp#setMaxVelocity_float_void

Link to comment

Thanks,very helpful . @cash-metall

I have no idea how to convert Player object to PlayerSpectator , one is base virtual class, one is derived class , why failed to convert ? 

The second line has error 

	Unigine::Player* myPlayer = Unigine::Game::get()->getPlayer().get();
	Unigine::PlayerSpectator* myRealPlayer =(Unigine::PlayerSpectator*)myPlayer;

	myRealPlayer->setMinVelocity(50);
	myRealPlayer->setMaxVelocity(100);

 

Edited by leon.dong
Link to comment

Find a stupid way to solve it . 

I modifed my code in UnigineScript

int init() {
	// Write here code to be called on world initialization: initialize resources for your world scene during the world start.
	
	Player player;
	PlayerSpectator tempPlayer= new PlayerSpectator();
	tempPlayer.setPosition(Vec3(0.0f,-3.401f,1.5f));
	tempPlayer.setDirection(Vec3(0.0f,1.0f,-0.4f));
	tempPlayer.setMaxVelocity(200.f);
	player=tempPlayer;
	engine.game.setPlayer(player);
	return 1;
}

 Still want response from offical support why error in C++ code.

 

Link to comment

im sorry it`s my fault:  i forgot about cast to PlayerSpectator

Unigine::PlayerPtr player = Unigine::Game::getPlayer();
if (player)
{
    Unigine::PlayerSpectatorPtr spectator = Unigine::checked_ptr_cast<Unigine::PlayerSpectator>(player);
    if (spectator)
    {
        specatator->setMinVelocity(50);
        // do something else
    }
    else
    {
        Unigine::Log::error("current player is not PlayerSpectator\n");
    }
}
else
{
    Unigine::Log::error("can not find MainPlayer\n");
}

 

  • Like 1
Link to comment
×
×
  • Create New...