Jump to content

[SOLVE]How do I make something controlled by certain keys?


Borislav
 Share

Recommended Posts

34 minutes ago, JohnK said:

Is this of help? http://www.babylonjs-playground.com/#102TBD#33

This method allows for two keys pressed  at once but one at a time is ok.

Lines 139 to 149 check for keys down or up, action for keys in registerAfterRender loop.

It is actionmanager, okay...

But; this is something different I am wanting the character to move and this all is really confusing since there are some ifs and e.t.c...

Do you know how to simply make something like an object moving?

Link to comment
Share on other sites

Only way I know is with the ifs

if(map["W"] || map["w"]) {
    character.position.y +=5;
}

Have a go at a simple playground and ask again if necessary.

You can find a more on using actions and using keys as triggers at http://doc.babylonjs.com/tutorials/how_to_use_actions#triggers (again more ifs - they really are needed)

Basic character control using keys with javascript at http://www.gaminglogy.com/tutorial/controls-keyboard/

 

Link to comment
Share on other sites

16 hours ago, Borislav said:

Do you know how to simply make something like an object moving?

Like this?: http://www.babylonjs-playground.com/#Z7U9QE

If you need physics, collision detection etc. you'll need a physics engine, too.

Babylon has built-in tools for that. You won't exactly come a long way without if statements and conditions, so if they confuse you, read up on them. There are millions of resources for just that.

Link to comment
Share on other sites

2 hours ago, Raggar said:

Like this?: http://www.babylonjs-playground.com/#Z7U9QE

If you need physics, collision detection etc. you'll need a physics engine, too.

Babylon has built-in tools for that. You won't exactly come a long way without if statements and conditions, so if they confuse you, read up on them. There are millions of resources for just that.

Fantastic, just what I needed!

I have a physics engine :).

Thank you.  

Link to comment
Share on other sites

4 hours ago, JohnK said:

Only way I know is with the ifs


if(map["W"] || map["w"]) {
    character.position.y +=5;
}

Have a go at a simple playground and ask again if necessary.

You can find a more on using actions and using keys as triggers at http://doc.babylonjs.com/tutorials/how_to_use_actions#triggers (again more ifs - they really are needed)

Basic character control using keys with javascript at http://www.gaminglogy.com/tutorial/controls-keyboard/

 

I meant that it is like: if(d = || asa = sft||Fds)

Link to comment
Share on other sites

Hi guys, sorry to butt-in.  @Borislav (and anyone else interested)... I once created a strange keypress listener system. It is different and somewhat weird.

http://playground.babylonjs.com/#2DYPYK#6

Weird, but easy to program... maybe.

Put lines 17-44 into your code.  You MUST have jQuery installed, because of lines 103-104.  I THINK that can be changed... so you don't need jQuery.  Haven't tried.  Also include lines 101-116... in your project.

Notice how I create a "movement function" such-as rotateCCW() in lines 90-94.  After that function, you see...

	keymaster.csz = rotateCCW;
	keymaster.sz = rotateCCW;
	keymaster.z = rotateCCW;

That means... control-shift-z (csz), AND shift-z (sz) AND z ... all will run rotateCCW() function.  Understand?  I hope so, because I really don't.  :D  This system is NOT WELL TESTED AT ALL.  You have been warned.  :)

But, somehow, it works, and it's easy, and nice code to read.  NO PROMISES about how intelligent this is.  Possibly dangerous.  Might blow up.  heh.  Keymaster property names... must have their "characters" in alphabetical order.  a=alt, c=control, m=meta, s=shift... and of course, bucky-less (plain ol' z).

Borrow at-will.  It is MOSTLY made for projects that have MANY MANY keypresses allowed.  AND... perhaps avoid ALT.  In recent tests, using ALT key caused "mesh not found" errors.  Not sure why, yet.

Also, control-shift-w is Windows "close this window" hotkey, and I haven't learned how to stop it, yet.  So, maybe avoid control-shift-w, for now.  Party on!

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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...