Jump to content

How to get the player to memorize position?


Woff
 Share

Recommended Posts

Please tell me how to get the player to memorize the position (left / right)? Let me explain what I mean: Let's say I want to shoot a potential enemy, I have a number of conditions for to make a shot:

if (cursors.left.isDown)
{
bullet.body.velocity.x = -400;
}
else if (cursors.right.isDown)
{
bullet.body.velocity.x = 400;
}
else {
bullet.body.velocity.x = 400;
}

Now if i turn left/right, my character begin to run in this direction :(
Based on the above, it turns out that the bullet flies only in the direction in which I pressed the button (left or right).

I would like that when you press the "left", my character has remained in this position until I press the "right" (or any other).


Thank you, any ideas?

Link to comment
Share on other sites

Can't really tell what your problem is from the description. It sounds like a top-down shooter. A simple image explaining what you are trying to do is often far more useful, maybe give an example of a game that does what you want.

 

Either way it sounds like a basic logic problem. It sucks, but it is just one of those things that you have to figure out for yourself. What I often do is draw my problem out on paper. Getting a visual understanding of what is going on helps a lot.

Link to comment
Share on other sites

Can't really tell what your problem is from the description. It sounds like a top-down shooter. A simple image explaining what you are trying to do is often far more useful, maybe give an example of a game that does what you want.

 

Either way it sounds like a basic logic problem. It sucks, but it is just one of those things that you have to figure out for yourself. What I often do is draw my problem out on paper. Getting a visual understanding of what is going on helps a lot.

Thank you for you reply, i will attach screenshot, hope it will be more informative.

When key  "left" is down, the bullets fly in left direction, but character runing in this direction too(!). (x = -400 so bullets fly there what it's need)

But when key left not isDown, by default bullets fly in right direction (x = 400) (is positive)

I think it would be great that character looked in that direction, what direction key was pressed last ce1a17772308.png

 

 

 

 

In example with Mario we can see his position and potential direction of moving:

By default his direction "right", but if we pass "left" button (even once), his head rotated in the opposite direction and remains there

85f817166b07.png

Link to comment
Share on other sites

Its still a little hard to understand what you want to achieve and what the problem is.

If you wanna remember the direction of your character before shooting in a diffrent direction than running

you could set a variable for direction that is only changed when not shooting while changing direction, or something like that.

 

it really depends on what you actually want to achieve,and thats not clear at least i don't get it..

regards

Link to comment
Share on other sites

 

If you wanna remember the direction of your character before shooting in a diffrent direction than running

you could set a variable for direction that is only changed when not shooting while changing direction, or something like that.

 

Yes, i think i need somethink like this. Thank you

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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