Discord
Login
Community
DARK THEME

Bullet position

In my current project, everything works fine except that even after I shoot the bullet, it updates the rotation.I can't figure out what is wrong with it

Here's the code for the bullet

initBullet = function() bullet = object x = 0 y = 0 speed= 3 active = false rota = player.rota end bullet.direction_vector = angleToVector(bullet.rota) end

updateBullet = function()
 
  if keyboard.SPACE and bullet.active == false then
    bullet.x = 5 
    bullet.y = 0  
    bullet.active = true
    after 2 seconds do 
      bullet.active = false
    end
    
  end
  
end


movingBullet = function()
    if bullet.active == true then
      bullet.x += bullet.direction_vector[0] * bullet.speed
      bullet.y += bullet.direction_vector[1] * bullet.speed
    end
  
    wrap(bullet, 3)
  end




drawBullet = function()
  if bullet.active == true then
   screen.fillRect(bullet.x, bullet.y, 3,3, "rgb(207,173,56)")
  end
end

also here's the link to see it visually, its supposed to resemble the Atari asteriods https://microstudio.io/Tikitotem/hjhbj/XZMTHJ27/

I think I've found the issue. SO, the problems lies with how I'm drawing all of this in the draw function of the main file. The player is made of a polygon, so I am using the setTranslation func to change the center of screen to the player's position and setRotation so the polygon is rotated at the players position. But since the there is both a translation and rotation, when Im drawing the bullet, it gets affected by both of these funcs. TO solve this, I need to make it so I get the point where the bullet spawns on the player AFTER the translation and make that the new spawn place. THEN I need to make it so the bullet isn't affected by the to "set" funcs mentioned earlier. if anyone comes up with a simpler solution let me know please!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community