This will be hard for you, maybe. Im using Nature2D to make my 2d game. To move some object that is non-anchored you need to create a RigidBody with using Nature2D, after you can set force for this part, like, :ApplyForce(x,y). Using this system I wanna make a bullet (like hitbox), so, idk how do i can correctly use :ApplyForce for this. To spawn the bullet, I use starterPos and another things.
first you want to get the direction to the mouse
this is simply done by subtracting the mouse’s screen position (should be a vector2) by the player’s position, or gun’s fire part
(mousePos - playerPos).Unit
(if this direction turns out to be backwards, just flip playerPos and mousePos so mousePos subtracts from playerPos)
then you want the speed of the bullet, which in your case is a consant value, ill use 10 for this example
idk if nature2d has masses, so i just included it, if theres no mass just remove it
local direction = (mousePos - playerPos).Unit
local speed = 10
local mass = 5
local force = bullet:ApplyForce(direction.x * speed * mass, direction.y * speed * mass)
well if you just plug this into the update function you will get the bullet following your mouse, so you would want to get the direction when the bullet is created and store that somewhere and update the bullet using that direction
already used starterPos instead of plrPos
well you want the direction to always be aligned with the player, starterPos seems like it never moves
btw, how do I can convert scale to offset correctly, cuz i tried and bullet have beed spawning in the bottom of the world. I wanna make starterPos gun handle pos, but handle pos is scale, not offset.
so if you google that theres two functions that convert it perfectly
uh, nothing
print your direction and make sure the speed isnt a huge number that it just teleports off screen
send a picture of your direction print and where your gun is aiming when you do it
nah, problem only in position, cuz, look at this. Vid without using scale to offset:
this is with using scale:
nvm
either your position or size is converted wrong or your size became a null number or so small that its invisible
what did you input into the conversation functions
your position is an offset, so you are converting an offset to an offset making it a huge number
use offset to scale not scale to offset
also are you sure natute2d doesnt do the conversions already or automatically edit offset values to fit to any size screen?
wait, wdym? All the rigid bodies using offset to detect pos or idk. Like, yeah, all the things in nature2d using offset
if the bullet works with offset positions why switch it to scale?
scale in ui is used to make it look the same size no matter the size of the screen
scale positions are 0-1 and its a percentage through the screen
offset positions are the raw pixel positions (0-whatever the width/height of your screen is)
yeah, ik what is scale and how to use it. But Nature2D uses offset only. Like, when you start the game and all the frames, that had scale pos, converted to offset pos
well then keep it in offset because i think nature2d already scales with the screen size
yeah, but, how do I can correctly do scale to offset correctly. I also cant find the part, that switch scale to offset (in nature2d)
Yay, I found this part finally
if you have a pixel position (offset) use the offset to scale method
if you have a scale position (0-1) its already in scale no need to change
if you want offset positions just convert scale positions to offset with scale to offset and leave offset positions alone