Author Topic: map inputs  (Read 10219 times)

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
map inputs
« on: 2007-11-27, 04:47:43 PM »
did you ever notice, that the "map player to inputs" method has almost entirely different effects as if by using "map key to input"?
i wanted to make a bag hanging on the belly of my player sprite. the bag is a sprite that is added. i mapped key inputs to it, then added the same speed and the same inertia. the bag is flying around almost as it has a own will. after setting the same "map key inputs" to my player, it is fine.

how comes this? i guess it's a feature, not a bug, but i would like to know.
and maybe it's possible to use sth like "map player to inputs" to any sprite, without using a rule for every key.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: map inputs
« Reply #1 on: 2007-11-28, 07:31:24 AM »
MapPlayerToInputs is a more complete function, and is recommended over MapKeyToInput.  MapKeyToInput is a very simple function that only sets an one input on a sprite.  MapPlayerToInputs will map all the keys and properly manage the "oldinputs" value and clear the previous inputs.  If you are using only MapKeyToInput, then your input is probably never cleared, so once a key is pressed the sprite will think it is always pressed (you need to also use ClearInputs if you use MapKeyToInput).  You might want to read the documentation about the MapKeyToInput, MapPlayerToInputs and ClearInputs functions (and the related help pages that these link to) to understand it better.

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: map inputs
« Reply #2 on: 2007-11-28, 04:23:23 PM »
when i only create a rule with "clearinputs", the player won't move. setOldInputs -> true or false doesn't changes a thing.
i also discovered "copyInputsToOld" for plans, but that also changes nothing.
the help file isn't very lenghty about the topics you mentionend.

do i have to build a rule that applies ClearInput after every key pressed?
could you please show me how to script that?
« Last Edit: 2007-11-28, 04:50:23 PM by Morgengrauen »

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: map inputs
« Reply #3 on: 2007-11-28, 06:29:24 PM »
maybe i am wrong, but can it be that the player moves faster when hitting left/right + up/down at the same time?
i think i hadn't noticed if i hadn't created treadmills for 16 directions myself. am i understandable?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: map inputs
« Reply #4 on: 2007-11-28, 09:59:51 PM »
when i only create a rule with "clearinputs", the player won't move. setOldInputs -> true or false doesn't changes a thing.
i also discovered "copyInputsToOld" for plans, but that also changes nothing.
the help file isn't very lenghty about the topics you mentionend.

First I should ask, why do you want to use ClearInputs and such instead of simply using MapPlayerToInputs?  MapPlayerToInputs is much better and allows the player to control how the game works.  If you use MapKeyToInput, then there is no point in the player options dialog, right?

do i have to build a rule that applies ClearInput after every key pressed?
could you please show me how to script that?

No, you don't ClearInput for every key. I think it goes like this:
ClearInputs(true)
MapKeyToInput(...)
MapKeyToInput(...)
...
MapKeyToInput(...)
AccelerateByInputs(...)

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: map inputs
« Reply #5 on: 2007-11-28, 10:10:36 PM »
maybe i am wrong, but can it be that the player moves faster when hitting left/right + up/down at the same time?
i think i hadn't noticed if i hadn't created treadmills for 16 directions myself. am i understandable?

It depends how you are limiting the sprite's speed.  If you only specify a Max value for AccelerateByInputs, then dx can go up to Max and dy can go up to Max.  If Max is 5, then dx can be 5 and dy can be 5.  Sqrt(5*5+5*5) is about 7, so you are actually going 7 pixels per frame diagonally instead of 5 pixels per frame.  If you want the limit to be applied to the sprite's vector instead of individually to the x and y velocity, you could use LimitVelocity.  I think that affect's the vector velocity instead of the x and y velocity independently.

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: map inputs
« Reply #6 on: 2007-11-30, 07:28:13 AM »
can i suspend the limitVelocity (or any other) rule by script? (there are facilities where i don't want to limit velocity, e.g. when the player travels in an air stream)

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: map inputs
« Reply #7 on: 2007-11-30, 09:21:40 AM »
I was looking for a similar type of functionality when creating a sprite recently.  What if it's just a regular walking sprite that can go x pixels per frame, but if it gets shot, it falls back at the speed of the bullet, which is faster.  How would you go about doing that?
Edward Dassmesser

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: map inputs
« Reply #8 on: 2007-11-30, 12:51:18 PM »
don't know... maybe "mapPlayerToInputs" is somewhere in the source code defined. maybe one can change that Sqrt(5*5+5*5) thing, so one doesn't need that LimitVelocity.
otherwise i would be very happy to have a method to suspend a rule by scripting. i would do this whenever the player hits the air stream tiles.

but durnurd, the max velocity for LimitVelocity is a value you could change maybe whenever the player is shooting. how does that sound?

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: map inputs
« Reply #9 on: 2007-11-30, 05:42:30 PM »
The idea is that I want the player to be able to accelerate themselves up to x pixels per frame from whatever speed they're going at.  Something similar to the platform local dx and dy, but without the platform.

Could your problem be solved by simply putting an If (not touching air stream tiles) before it?
Edward Dassmesser

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: map inputs
« Reply #10 on: 2007-11-30, 06:01:32 PM »
that is indeed a good idea ;D
but i would prefer it, when it is possible, the player not to go diagonally faster only in the airstreams. it is somehow unfair, because when you (as the air ship) are fighting against an air stream, there is an fluky advantage when you hit 2 keys at the same time, instead of just hitting up or left.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: map inputs
« Reply #11 on: 2007-12-01, 09:35:17 AM »
If you use the LimitVelocity rule, there is no bug.  It does limit the velocity correctly in any direction.
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: map inputs
« Reply #12 on: 2007-12-01, 11:33:22 AM »
can i suspend the limitVelocity (or any other) rule by script? (there are facilities where i don't want to limit velocity, e.g. when the player travels in an air stream)

If you want to be able to suspend a rule at runtime, you must make the rule activated by a parameter or a counter.  For example:
Code: [Select]
if limitVelocity=1
   limitVelocity(5)

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: map inputs
« Reply #13 on: 2007-12-01, 11:43:08 AM »
If you use the LimitVelocity rule, there is no bug.  It does limit the velocity correctly in any direction.

i know, i talked about your tip only to limit velocity when not touching an air stream. that means in the air streams one diagonally moves faster.

i would need to limit the players velocity whenever he moves by himself. when another force is hitting him, he is moved faster than he could do alone.

bluemonk, i'll try that.

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: map inputs
« Reply #14 on: 2007-12-17, 03:08:42 PM »
i can't figure it out.
i just tried to make two limit velocities, the first works when the player moves normally around (max speed 4), the second when he hits an air stream tile (max velocity 10).
but it's the same. when in the air stream, the player can move diagonally faster than he should.