Jump to content

How to give locomotion to a character


Vida Marcell
 Share

Recommended Posts

The only thing I can think of is to have a beam coming out of each player's foot and these detect when the player touches the ground.  If one doesn't touch the ground depending on the leg it could trigger an animation that is one foot lower. 

Possibly there is another better way to do it.

 

 

Link to comment
Share on other sites

2 minutes ago, Yue said:

The only thing I can think of is to have a beam coming out of each player's foot and these detect when the player touches the ground.  If one doesn't touch the ground depending on the leg it could trigger an animation that is one foot lower. 

Possibly there is another better way to d

This is smart. But i think i will focus on blending the animations. Integrating havok would help. but if someone notices it Havok will beat my ***.

Link to comment
Share on other sites

HI, you can attach a lua script from the editor. If you have the profesional edition and you are using VSxxx and cpp you may interact with world elements created on the editor, call lua functions in the object's script, pass parameters, receive etc.

 

I wrote this some time ago, don't know how much outdated it may be, but perhaps it will be a starting point:

 

Juan

  • Like 2

Paren el mundo!, me quiero bajar.

Link to comment
Share on other sites

1 minute ago, Charrua said:

HI, you can attach a lua script from the editor. If you have the profesional edition and you are using VSxxx and cpp you may interact with world elements created on the editor, call lua functions in the object's script, pass parameters, receive etc.

 

I wrote this some time ago, don't know how much outdated it may be, but perhaps it will be a starting point:

 

Juan

Thank you very much!

Link to comment
Share on other sites

Allright, can someone tell what am i doing wrong here is a part of my code:

//Load a prefab
	Entity* player = Prefab::Load("Prefabs/player.pfb");
	player->SetPosition(0, 6, 0);
	player->SetSweptCollisionMode(true);

	Camera* camera = Camera::Create(player);
	camera->SetPosition(0, 2, 0);
	float playerheight;

	window->HideMouse();

	float walk;
	float turn;
	float jump;
	float jumpspeed = 8;
	float speed;
	bool cdown = 0;

	Vec3 mouse = Vec3(0, 0, 0);
	Vec3 velo = Vec3(0, 0, 0);
	Vec3 camera_y = Vec3(0, 0, 0);

	float mouse_x;
	float mouse_y;

	float lerp;

	while (true)
	{
		camera->GetPosition();
		camera_y = camera->GetPosition();

		mouse = window->GetMousePosition();
		window->SetMousePosition(window->GetWidth() / 2, window->GetHeight() / 2);

		mouse_x += (mouse[0] - window->GetWidth() / 2) / 4.5;
		mouse_y += (mouse[1] - window->GetHeight() / 2) / 4.5;
		
		camera->SetRotation(mouse_y, 0, 0);

		walk = window->KeyDown(Key::W) *speed - window->KeyDown(Key::S) *speed;
		turn = window->KeyDown(Key::D) *speed - window->KeyDown(Key::A) *speed;
		speed = 5 + window->KeyDown(Key::Shift) * 2 - window->KeyDown(Key::Control) * 3.5;
		
		lerp = Math::Lerp(2, 0, 0.5);
		
		if (!window->KeyDown(Key::ControlKey) && cdown == 1)
		{
			cdown = 0;
			speed = 8.0;
			camera->SetPosition(0, 1.75, 0);
		}

		if (window->KeyDown(Key::ControlKey) && cdown == 0)
		{
			cdown = 1;
			speed = 4.0;
			camera->SetPosition(0, lerp, 0);
		}

		velo = player->GetVelocity();
		if (velo[1] == 0.0)
		{
			jump = window->KeyHit(Key::Space) * jumpspeed;
		}
		else
		{
			jump = window->KeyHit(Key::Space) * 0.0;
		}

		player->SetInput(mouse_x, walk, turn, jump, cdown, 1, 1, true);
		
		if (window->Closed() || window->KeyDown(Key::Escape)) return false;
		Leadwerks::Time::Update();
		world->Update();
		world->Render();
		context->Sync();
	}
	return 0;
}

 

Link to comment
Share on other sites

lerp = Math::Lerp(2, 0, 0.5);
will always make the player height zero

lerp = Math::Lerp(camera->GetPosition().y, (playerheight*cdown ), 0.5);

does this make sense to you ? camera->GetPosition().y, may be wrong but you need to get the y part of the vector of getposition
also you need to remove (makes no sense):

	while (true)
	{
		// remove this line camera->GetPosition();
  • Like 1
  • Thanks 1
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...