Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a better way to move my projectile than BodyPosition?

I tried using BodyPosition, which works ok but the thing is with BodyPosition when I click on something the projectile doesn't travel in a straight path (or if i dont click on anything the projectile flings itself to who knows where)

Here's what I used:

projectile.BodyPosition.Position = Mouse.hit.Position

I don't think BodyVelocity will work either, because I don't want the projectile to just go forward in the direction the player is facing, but for it to be shootable in any direction (towards the mouse).

I also don't think raycasting will do the job either (Although I may be mistaken) because everything i've seen on raycasting so far just shows like a laserbeam towards the mouse that disappears after a second and not really anything projectile based.

So, is there a better way to move my projectile? If so, what?

edit: I also don't want it to travel in an arc either

6 comments

0

BodyVelocity travels in world axis. If you know what direction vector the projectile will be moving in (in your case, the vector unit of the position the mouse is pointing at MINUS the character's position), you can multiply that value by a speed and the BodyVelocity will apply force to the part in that direction.

0

A pseudo-example could be: BodyVelocity.Velocity = (Mouse.hit.Position - Handle.Position).Unit * SPEED --handle would be the base of whatever your using to shoot the projectile with

0

wow

0

@kamoojan the legend

0

I use this "BodyVelocity.Velocity = CFrame.new(Handle.CFrame.p + Handle.CFrame:vectorToWorldSpace(Vector3.new(0, 0.4, -1.1)), Mouse.Hit.p).lookVector * 100 --[[ Speed ]]"

0

@pidgey @OnaKat thank you guys a ton

1 answer

✓ Accepted answer

It is possible to "segment" rays to get a projectile speed effect. The projectile (ray) travels 10 studs (in this example) then stops, if it doesn't hit something it continues where it stopped. If however it does hit something it will stop.

I don't remember how to do this on the top of my head but i recommend that you should look into raycasting.

1 comment

1

thank you kind gamer

This discussion is preserved as it was. New answers, comments, and votes are closed.