ID:1270982
 
(See the best response by Kitsueki.)
Problem description:

I am trying to do a simple galaga type of game for practice and I have some projectile code set up. It works perfect, and displays the bullet properly if the player does not move, but once the player moves the bullet starts to appear more to the left and looks akward. Does anyone know a way to keep the projectiles loc from sliding over?

This is the code for the projectile:

    standard
icon_state = "standard"
bound_height = 4
bound_width = 4
pixel_x = 5
pixel_y = 4
step_x = 10
step_y = 32

New(mob/shooter)
loc = shooter.loc


It appears that pixel movement is on and that is why it is doing this, but I need the smaller bounding box for the icon or I will have to set up 4 sepereate .dmi files which seems less efficient.
Best response
Pixel movement would be active here, yes.
You need to set bound_x and bound_y for this. pixel_x and pixel_y are visual offsets, they don't change the bounding box at all.

You need to set the step_x and step_y values once the projectile is created, to line it up with the player.
Still doing the same thing. I will try to give a rough idea of what it looks like.
P = player, s = bullet



(without any movement it looks like this)

s
p

(just the way I want it to look)

(Now when the player moves it looks like this)
     s
p

So if the player stops after moving and trys to shoot the bound x and bound y has shifted to the edge of the tile so now it looks like the shot is coming from a strange place which then causes misses because of where the shot should have came from is not where it comes from.
That begs for you to show us your movement code.
I haven't changed any of the movement code. I figured maybe it was because the player's mob still had glide, or non pixel movement so I changed the players bounding boxes as well but it still gives the error.

Upon closer inspection I see that what is happening is the shot icon is being displayed in the middle of the turf icon infront of the player. So if the player moves left to right it does not matter because the shot icon stays in the center of that turf.
In response to Akando5959
That's what I said, you need to position it when the projectile is created. Determine the shooter's step_x and step_y values, then apply them to the projectile. It can be a little complicated, but it is the solution.

I typically solve that by doing something like

position(obj/o, mob/m)
var nx = m.step_x, ny = m.step_y
if(m.dir & NORTH) ny += m.step_size
if(m.dir & SOUTH) ny -= m.step_size
// carry on
// now do this
o.loc = m.loc
o.step_x = nx
o.step_y = ny
So anytime we are refering to a player's x or y cord we should be using step_x or step_y instead of pixel_x or pixel_y?
    proc
BulletLife()
while(src.y < world.maxy)
walk(src, NORTH, 1, 5)
sleep(3)
CheckLoc(src)
Position(obj/shot, mob/shooter)
var

newY = shooter.step_y

shot.loc = shooter.loc

shot.step_y = newY
shot.bound_height = 2
shot.bound_width = 1
shot.bound_x = 2
shot.bound_y = 3
shot.step_x = 20
shot.step_y = 32


    standard
icon_state = "standard"



New(mob/shooter)
..()

Position(src, shooter)
spawn(1)
BulletLife()


I tried doing the bound, pixel, step changes in under the shot dec., but it ingored this and would create the shot obj at its normal location as if bound_x or bound_y was never set. If I set it inside of the position proc directly then it acts as before using just:

New(mob/shooter)
src.loc = shooter.loc


The reason I did not include the details of If north or south is because the player can only move East or West so it would be redundant.
I can not get it to let me post a screen shot so here is best attempt.

p = player | equal turf edge, s equal shot

|  s  |
P


|  s  |
| P |


In response to Akando5959
You're confusing bound_x and bound_y, they're not meant for that. Look them up in the reference if you haven't already. You want to set step_x and step_y for this proc.

Call Position() in the New() proc for the projectile, right before you have the AI start doing anything.

Now, you have to calculate the proper step_x and step_y positions. Just start from the shooter's location and add onto their step vars, if the step vars overflow past 32 they'll adjust themselves and set to the right location, so don't worry about that.
I forgot to take that part out again, but I have it with just step_x and step_y. The icon appears infront of the player, but it still does the same thing. The shot is going down the middle of whatever turf model that the ship is on. So if the ship is slightly on the turf to tis right then thats the turf the shot travels in.

So the shot is not correctly going to the x and y cords of the ship, but rather into the contents of the turf.

If I take out the step_x and step_y of the projectile then the shot shows to the players bottom right as in the icon file for the shot it is in the bottom right of the file.

I have to change step_x to around 10 for it to look correct when the player does not move.

I also realised I took out the x cords but I should have taken out the Y, which I correct to have:

    Position(obj/shot, mob/shooter)
var
newX = shooter.step_x


shot.loc = shooter.loc

shot.step_x = newX
shot.bound_height = 2
shot.bound_width = 1
shot.step_x = 10
shot.step_y = 32


I am calling the position proc before the proc that moves the shot so that way when it generats it should generate infront of the player.
In response to Akando5959
Why are you setting step_x twice?
This wont put it in front of the player, at best it would lay it on top of the player. Look at how I was doing position().

The projectile appears centered in the icon file I hope.
Oops... I missed that second step.x, thank you for that.

shot.step_x = newX + 10


This is what I ended up with for it and now the shot appears directly in front of the players icon correctly even when they move.
Thank you very much.