Hello,
I’m trying to create a leap ability for a boss npc in my game. When the ability is activated, the npc will leap towards the target position in a curve.
The effect I’m looking for is similar to this video:
Hello,
I’m trying to create a leap ability for a boss npc in my game. When the ability is activated, the npc will leap towards the target position in a curve.
The effect I’m looking for is similar to this video:
You’re looking for projectile motion modelling
Yes, I’ve tried the methods from that post step by step before. but sadly physical (I mean directly apply velocity) way are barely works on npc,but this is exactly what i want to achieve
There are many parabolic orbits which reach a particular point.
I assume that there is no other power such as air resistance.
All they are in this condition:
x/v = 2u/g
(g is gravitational acceleration, v is parallel velocity, x is the distance between player and boss, u is vertical velocity)
If you set all the values as they are in this condition, player always reach to the boss.
I may forgot the probability that the boss is moving.
I’m still having trouble understanding this. Could you explain it and show how I can use it in a script? (I’m beginner on scripting)
If simulating the parabolic trajectory is insufficient, you can manually interpolate the trajectory by creating a function of time that maps out its positions:
local function getPositionAtTime(timePosition: number, origin: Vector3, initialVelocity: Vector3): Vector3
local displacement = initialVelocity * timePosition + 0.5 * GRAVITY_ACCELERATION * timePosition ^ 2
return origin + displacement
end
Related kinematic equation:
I’m not a native English speaker, so the description may be hard to understand.
· gravity can be got from Workspace.Gravity
· distance between player and the boss can be got from Player:DistanceFromCharacter(Boss.Position)
· You can add velocity by ApplyImpulse.
· Parallel Vector of ApplyImpulse should be parallel to Boss.Position - Player.Position (But z component isn’t). Then, Parallel velocity(v) can be set as
t*(Boss.Position.X - Player.Position.X, Boss.Position.Y - Player.Position.Y, 0) (t can be any number you like)
Vertical velocity(u) should be in this condition:
u = gx/2v
so Z = gx/ParallelVector.Magnitude*2
Thus, the Vector you should apply is found.
In conclusion:
local g = workspace.Gravity
local boss = workspace.Boss --your boss
local t = _ --whatever value you like
local function attack(player, boss)--[[player is who used the ability]]
local humanoid = player.Character:FindFirstChild("Humanoid")
if not humanoid then return end
local root = humanoid:FindFirstChild("HumanoidRootPart")
local x = boss.Position - player.Position
local ParaV = Vector3.new(boss.Position.X - player.Position.X, boss.Position.Y - player.Position.Y, 0) *t
local u = g*x.Magnitude/2*ParaV.Magnitude
local TheV = Vector3.new(boss.Position.X - player.Position.X, boss.Position.Y - player.Position.Y, u) --This is the Vector applied to player
root:ApplyImpulse(TheV *t)
end
I forgot to use this, so you can write as:
local x = player:DistanceFromCharacter(boss.Position)
local ParaV = Vector3.new(boss.Position.X - player.Position.X, boss.Position.Y - player.Position.Y, 0)
local u = g*x/2*ParaV.Magnitude
Instead of
Thanks, but the caster of leap ability is npc instead of player (player is target)
I made a mistake. This script can be used only in the case that Z Position of player and the boss are same.
Improved idea:
h is the deference of Z Position of player and that of boss.
u +√(u^2 - 8gh)/g = x/v
If you want a script, I will reply later.
For this, Just change Player and Boss.