How to move an actor relatively to its own position?

yankleber

  • Posts: 11
Hi,

I am a dinosaur coder used to code heavily directly in AS (Flash) then I am bumping to some small barriers in this new way to develop. Actually I feel ashamed to ask such simple things, but I have tried several possible solutions and it is not working for me.

So I am facing this problem that normally can be done easily programmatically. I am making this very simple shooting game (for learning) so I am using a couple resources I downloaded from StencylForge -- a ship (actor) and a laser fire (actor behavior). OK, it kind of works, but whenever I fire the laser the shot does not appear centered to my ship and I would like to correct it.

I tried to open the laser fire behavior and adjust the shot x-position in a few pixels by adding an "actor > position > set [] to [...]" and setting the "to" attribute to "x+5" but it doesn't recognize the "x" as a valid variable.

Actually what I am trying to do is to move an actor to a relative position and not to an absolute one and I cannot see how to do that. Any thoughts?

Thanks!

Kiki123987

  • Posts: 29
I'm not sure if this is what you want, but I'll give it a try.

So you want an actor to be moved (for example) 100 pixels up and 100 to the left, without giving it a absolute position to be moved to?

If you do so, you could try to play around with "x of Actor" found unter Actor -> Position. You can replace the x with y, x-middle, etc. So you get the position of this Actor and then you move it to (for the example mentioned above) the old x-position - 100 pixels and the old y-position + 100 pixels

yankleber

  • Posts: 11
Thanks for your try, Kiki, but it doesn't work because you cannot use an expression such as "x-center" (or whatever). It causes a compilation error.

rob1221

  • *
  • Posts: 9472
You don't type in "x" or "x-center".  There's a block for that.

Kiki123987

  • Posts: 29
Yeah thats what I meant. The block can be found under Actor -> Position

Nomosoft

  • Posts: 122
Check the screen shot at the bottom of my post. Your block should look something like that. I have a feeling you are filling in text where you should be using more blocks.

Edit: Or not, given your last reply. Post a screenshot of your modified action.
Edit 2: Those should not both say "self," I just slapped the block together as an example.

yankleber

  • Posts: 11
Sorry guys, seems that I didn't make myself clear enough...

 :P

I want that whenever a new "Shot" be instantiated, that it be positioned initially at the same x position of the "Ship" plus 5. For instances:

Ship.x = 100
Shot.x = Ship.x + 5 (Therefore Shot.x will be 105)

Ship.x = 290
Shot.x = Ship.x + 5 (Therefore Shot.x will be 295)

And so on...

Does it make any sense for you guys?

I couldn't find a way to input such expression using the referred block or any other block.

 :(

Thanks!

yankleber

  • Posts: 11
Check the screen shot at the bottom of my post. Your block should look something like that. I have a feeling you are filling in text where you should be using more blocks.

Never mind! I finally got it. Yes, Nomorsoft -- your example is perfect! It solved my issue.
Thanks a LOT!

 :D