Scrolling Game Development Kit Forum
SGDK Version 2 => Help, Errors, FAQ => Topic started by: Tanja 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.
-
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.
-
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?
-
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?
-
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(...)
-
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.
-
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)
-
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?
-
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?
-
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?
-
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.
-
If you use the LimitVelocity rule, there is no bug. It does limit the velocity correctly in any direction.
-
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:
if limitVelocity=1
limitVelocity(5)
-
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.
-
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.
-
Does that mean that the rule you made for limiting velocity in an air stream is not being applied? You just have to figure out why it isn't being applied, right? Did you set the counter wrong?