BlueThen commented on a Page, Zombie Shooter (Updated 06/11/13)  -  Dec 17, 2011

I took a look into your code, and I think I can help you with the aiming.

I would be more specific on the code, but I haven't coded in mSL in a long time, so most of this will be pseudo code.

There's two ways of doing this. You could find the angle between the player and the mouse, and use
speed cos(angle) for the x component of the velocity, and
speed
sin(angle) for the y component.

OR, you could normalize the difference between the mouse and the player, and then multiply that by speed.
This can be achieved through these steps:

; find the difference between player and mouse position
deltaX = playerX - mouseX
deltaY = playerY - mouseY

; find the distance by using the differences
distance = sqrt( deltaX ^ 2 + deltaY ^ 2 )

; normalize the differences (this shortens the deltaX and deltaY so that their distance = 1)
normX = deltaX / distance
normY = deltaY / distance

; next, you can multiply by whatever speed you'd like
velX = normX * speed
velY = normY * speed

; Add the bullet to your buffer
aline @ZBulletBuf %gt %zomb.px %zomb.py velX velY
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.