Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | GunPoint |
Stupid question here, i know…
So… I made a top-down character which can move north, south, east and west. I want him to be able to shoot bullets in those directions. I instanced the bullet, made a simple script so the bullet goes in the direction the player faced last time. The problem is, if i move the player, it’s direction changes… the bullet’s direction changes too
(i’ve been thinking of a solution to this problem for almost 2 days… lack of exercises)
I thought of storing in a variable the direction the player faced when the bullet was shot. How can I do that?
The bullet’s movement
motion.y = -1 * BULLET_SPEED
set_position(get_position()+motion * delta)
This is for the north direction. Basically I checked the player’s direction and with an If, I would multiply the motion’s x or y with -1 or 1 depending on the direction
I know, this is the most stupid way to do it… i’ve tried others but I was unsuccesful
Is there a better solution?
I guess you added a bullet instance under the player node.
you should add the bullet node outside of player node.
volzhs | 2019-01-03 20:52
can you add more code? perhaps having full script of player and bullet would let us help you a little more.
p7f | 2019-01-04 18:50