Does anyone have any idea what projectile method is used in Magic Training wands?

Hello! Does anyone have any idea what method of projectile serphos uses in magic training? I assume its probably ray casting? I’m trying to gather ideas and inspiration on how to create a similar clashing and blocking system (obviously with my own flares, designs, and effects).

My guess is that when the player clicks ‘q’, that a value is activated in the player… if the ray detects that the player is blocking… then it will block the spell? Similar with clashing… if the player is within a certain radius from another player… and the player still is in a casting state… and you attack the other player at the same time… then the clashing commences. Does any of this sound right? Idk. Any other thoughts?

5 Likes

Yeah I would assume so. I haven’t played the game too much but when I hopped on I got a sense of it. When Raycasting he most likely checks if you hit a Player with your wand and from that player he checks if they are blocking via a boolval somewhere. Same thing with clashing. Definitely mess around with Rays if you are going to create and have fun with your own wands!

1 Like

I haven’t worked with ray casting projectiles before… any suggestions?

How do you use a raycasting for projectiles? Do i still use body Velocity and just use the raycasting as the indicator? Idk.

uhmm, you can use cframe:lerp or velocity, a lot of stuff lol

Check out an old post of mine, is how I make my own.

1 Like

Is your spellpart anchored? @KossmoZ

1 Like

It is, it works by setting the SpellParts LookVector into direction of the Mouse.Hit; it’s then moved forward along it’s LookVector until colliding.

@KossmoZ Is there a similar solution to this without so much loop? I mean it’s creating a lot of lag.

No love for TweenService? Well, I’ll bite. Basically, you’d use “Time Formula” (as highlighted here). It calculates the time based on the normal time of the tween (0.3 is what I’ve had the most success with), and you would multiply it by the magnitude of the difference between the projectile and the end position.

local tween = TweenService:Create(projectile, TweenInfo.new((mouse.Hit.Position - projectile.Position).Magnitude * TWEEN_TIME / TWEEN_VELOCITY, Enum.EasingStyle.Linear), {CFrame = CFrame.new(mouse.Hit.Position)})
tween:Play()
1 Like

I attempted this method and I quite enjoy it - How would I go about implementing an updating RayCast to detect collisions that will also remove my Part without delay?

The only other method I found was the one I mentioned above, but as said - It results in lag.

https://gyazo.com/5b6a17c56d02c55d2752d0bc93e02084

3 Likes

For me, I’d just hook it to a touched event and cancel the tween when the event is fired. If a humanoid is detected, then I’d take damage. Also, don’t forget to disconnect from the touched event when it’s fired.

Will the tweening reduce lag? And for the sake of argument… how would you connect raycasting to it?

He’s using Raycast to detect collsions with a projectile, however, in this case, Raycast collision detection is a overkill method for projectile hitboxes. It would make sense for melee, but it’s just best case scenario to use .Touched because none of the bugs are present in the situation.

And this will resolve some lag issues?

.Touched has always seemed to have a delay on it. Its the reason I began using RayCast to begin with - With RayCast and the method I used above, it made collisions seemless, although yes its not the most efficient.

However, using the Touched event seems to create a delay where the spell part appears to pass through the Player for a brief second before registering and removing.

I’ve had this before. My only issue with your previous method @KossmoZ, which i have been using… is it creates lag. Maybe its because too much is running through the code? would a repeate wait after the tween plays, detecting the ray be less taxing on the server if its only indexing the ray values… and hit values?

1 Like

I just tried the tweening thing… it doesnt seem to be triggerable for some reason. Touched isnt working, and i even tried for the sake of argument, loops behind the tweening just without the cframe moving with raycasting. :confused: not working.

1 Like

Apologies for the lack of indent as it was rushed.

Try this perhaps? Just an idea I had.

local RunService = game:GetService("RunService")

local RemoteEvent = Instance.new("RemoteEvent")

RemoteEvent.Parent = script.Parent

RemoteEvent.OnServerEvent:Connect(function(Player, TargetPos)

local SpellPart = Instance.new("Part")

SpellPart.Anchored, SpellPart.CanCollide = true, false

SpellPart.Size = Vector3.new(1, 1, 1)

SpellPart.CFrame = CFrame.new(Player.Character.Head.CFrame.p, TargetPos)

SpellPart.Parent = Player.Character

local IgnoreList = Player.Character

local SpellSpeed = 5

RunService.Heartbeat:Connect(function(step)

if not SpellPart then return end

wait()

local SpellRay = Ray.new(SpellPart.Position, SpellPart.CFrame.LookVector * SpellSpeed)

local Obj, Position = workspace:FindPartOnRay(SpellRay, IgnoreList)

if not Obj then

SpellPart.CFrame = SpellPart.CFrame + SpellPart.CFrame.LookVector * SpellSpeed

else

SpellPart:Destroy()

return

end

end)

end)
2 Likes

It’s definitely using raycasts with server-sides sanity checks. The projectiles are fired by the client and the distance is most likely traced by the server,

There’s a bunch of ways that you can achieve the zig-zag effect. One being, if you made a raycast from the wand’s tip to the part that’s hit (assuming that you’ve hit a part), you can think of it as the X-Axis of your graph where origin (0,0) is your wand’s tip. From there, you could create a sin-wave and have random values for it’s frequency.

I meant for the tweening… I have it working for the loop.