playMaker

Author Topic: how to set float or vector2 variable to previous value when it reaches 0  (Read 2665 times)

bizilux

  • Full Member
  • ***
  • Posts: 171
im in a bit of a pickle.

im starting video tutorial series about top down 2d shooter, but im having problem with shooting part.

for moving im using "get axis vector" which i then convert into vector2 and "set velocity 2d".

and then i use this vector2, and using it for shooting.

shooting is done with raycasts. i use raycast 2d, and for direction, i use "vector2".

everything works great and i can shoot when i am moving.
but when i am not moving, vector2 gets set to 0,0.  so obviously raycast direction then is 0,0 and that is a problem since it doesnt send raycast to any direction.

so how can i set raycast2d into direction where player was going before he stopped.


i tried setting vector2 variable, into another vector2 variable...
i also tried using vector2 compare, to compare when vector2 is 0,0 and then do something.

but i just cant figure out... im sure there is some simple way that i am not seeing...

basically vector2 has all of these values: 0,1  1,1   1,0   0,0   -1,0   0,-1  -1,1  1,-1  -1,-1
so yes, player can go into 8 directions, plus 0,0 which is standing still.  like i said, im having problem with standing still....

lets say player was going into direction 1,0  which is to the right.  so vector2 value would be 1,0.
and if player would want to shoot, bullets would go into 1,0 direction. which is to right. but the problem is when player stops, and his vector2 goes to 0,0. but player is still facing right. so if he wants to shoot then, he cant because vector2 is 0,0.
so how can i set vector2 variable back to whatever value it was before it reached value 0,0 ???
« Last Edit: August 27, 2014, 05:27:45 AM by bizilux »

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: vector2 problem. (2d top down shooter)
« Reply #1 on: August 27, 2014, 05:19:16 AM »
in case its hard to understand, lets simplify it:

i have a float variable that it values can be one of these 3:  1-, 0, 1

now when float variable is 0, i dont want it to be 0, i want it to be the last number that was before it turned 0.

so lets say it was -1, and then it turned 0.  i want float to be changed back to -1, or somehow save it into another float variable

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Thats all there is to it, really. Storing the original value before you manipulate it, then reverting when you feel like it.

In some actions this is done internally for various reasons, but something like what you're wanting would just be setup to store the value into a separate variable before it changes, then you have it available any time. A Compare action could fire the events either way.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

bizilux

  • Full Member
  • ***
  • Posts: 171
yes exactly, but the problem that im seeing right now...

i can use vector2 compare action... and i can set it up that it sends event every frame that vector2 is not 0,0. and in new state, it saves vector2 into another temporary vector2 that is there in case vector2 goes to 0,0

but im seeing some problems, first, it would be infinitive loop, and second, i really want to keep it all in one state, because im also firing raycasts from that state...

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: how to set float or vector2 variable to previous value when it reaches 0
« Reply #4 on: September 02, 2014, 04:20:28 PM »
still need help :(