Jump to content

How to increase the speed when I move camera via keyboard


photo

Recommended Posts

Posted

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. 

 

Posted

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

Posted (edited)

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
Posted

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.

 

Posted

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
Posted (edited)

May I ask where defined 

image.thumb.png.6ad119327a912824a0f2dbc4a744b952.png

Unigine::checked_ptr_cast
Edited by leon.dong
Posted

Confused , how to cast Player object to PlayerSpectatorPtr object in C++ codes......

 

Posted

I know what's wrong . 

My SDK version is v2.7..1 too old to use this new API dynamic_ptr_cast  

Is there any old API to do same thing ? 

Posted

in 2.7.1 it is 
PlayerPersecutorPtr persecutor = PlayerPersecutor::cast(player);

Posted

That works . thanks.

 

×
×
  • Create New...