Jump to content

Input not working correct


Andy90
 Share

Go to solution Solved by reepblue,

Recommended Posts

Hello :) im not 100% sure if its a bug but it feels like it. I try to change the position for my player. But however he gets teleported back to the old position. I use a slight modifyed version of the FPS Controls. 


How to reproduce:
Change the update function with the following code and press enter, wich sets the player to 0,0,0 and press any movement key after the position change. 
 

void FirstPersonControls::Update()
{
	Vec3 movement;
	float jump = 0;
	bool crouch = false;
	auto entity = GetEntity();
	auto window = ActiveWindow();
	if (window)
	{
		if (!freelookstarted)
		{
			freelookstarted = true;
			freelookrotation = entity->GetRotation(true);
			freelookmousepos = window->GetMouseAxis();
		}
		auto newmousepos = window->GetMouseAxis();
		lookchange.x = lookchange.x * mousesmoothing + (newmousepos.y - freelookmousepos.y) * 100.0f * mouselookspeed * (1.0f - mousesmoothing);
		lookchange.y = lookchange.y * mousesmoothing + (newmousepos.x - freelookmousepos.x) * 100.0f * mouselookspeed * (1.0f - mousesmoothing);
		if (Abs(lookchange.x) < 0.001f) lookchange.x = 0.0f;
		if (Abs(lookchange.y) < 0.001f) lookchange.y = 0.0f;
		if (lookchange.x != 0.0f or lookchange.y != 0.0f)
		{
			freelookrotation.x += lookchange.x;
			freelookrotation.y += lookchange.y;
			camera->SetRotation(freelookrotation, true);
		}
		freelookmousepos = newmousepos;
		float speed = movespeed;// / 60.0f;
		bool jumpkey = window->KeyHit(KEY_SPACE);
		if (entity->GetAirborne())
		{
			speed *= 0.25f;
		}
		else
		{
			if (window->KeyDown(KEY_SHIFT))
			{
				speed *= 2.0f;
			}
			else if (window->KeyDown(KEY_CONTROL))
			{
				speed *= 0.5f;
			}
			if (jumpkey)
			{
				jump = jumpforce;
			}
		}
		if (window->KeyDown(KEY_D)) movement.x += speed;
		if (window->KeyDown(KEY_A)) movement.x -= speed;
		if (window->KeyDown(KEY_W)) movement.z += speed;
		if (window->KeyDown(KEY_S)) movement.z -= speed;
		if (movement.x != 0.0f and movement.z != 0.0f) movement *= 0.707f;
		if (jump != 0.0f)
		{
			movement.x *= jumplunge;
			if (movement.z > 0.0f) movement.z *= jumplunge;
		}
		crouch = window->KeyDown(KEY_CONTROL);

		if (window->KeyDown(KEY_ENTER)) {
			this->GetEntity()->SetPosition(0, 0, 0);
			this->currentcameraposition = this->GetEntity()->position;
		}

	}
	entity->SetInput(camera->rotation.y, movement.z, movement.x, jump, crouch);
		
	float eye = eyeheight;
	float y = TransformPoint(currentcameraposition, nullptr, entity).y;
	float h = eye;
	if (y < eye) h = Mix(y, eye, 0.5f);
	currentcameraposition = TransformPoint(0, h, 0, entity, nullptr);
	camera->SetPosition(currentcameraposition, true);
}

 

Link to comment
Share on other sites

  • Solution

I'm able to teleport my player around fine in my project. Did you try entity->Sync()?

Ultra Engine - Best game engine for VR optimized for fastest virtual reality 3D performance

You might also want to try disabling the physics before the swap and then resetting it after. The idea is that you want the physics and rendering thread to catch up. Maybe this can be done internally? 

// Disable Physics
entity->SetPhysicsMode(PHYSICS_DISABLED);

// Swap the positions
entity->SetPosition(0,0,0);
entity->Sync();

// Renable Physics
entity->SetPhysicsMode(PHYSICS_PLAYER);

 

  • Like 2

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Yeah with the physics disabling and reactivating it is working. I was not expecting to do this. Maybe SetPosition() should do this allready. Or an Translate() function wich is doing this. Thanks Reep :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...