抛物线&轨迹算法

2020-06-02 15:03:02 浏览数 (1)

抛物线轨迹算法

local x1=startPos[1] local y1=startPos[2] local x3=endPos[1] local y3=endPos[2] local width=x3-x1 local x2=x1 width/2 local y2=y1-height

代码语言:javascript复制
local b=((y1-y3)*(x1*x1-x2*x2)-(y1-y2)*(x1*x1-x3*x3))/((x1-x3)*(x1*x1-x2*x2)-(x1-x2)*(x1*x1-x3*x3))
local a=((y1-y2)-b*(x1-x2))/(x1*x1-x2*x2)
local c= y1-a*x1*x1-b*x1
local vx=width/3--width单位长度/5s
local posx=startPos[1] vx*deltaTime
local posy= a*math.pow(posx,2)  b*posx   c

平抛运动

local dir=UnityEngine_Vector3.Normalize(UnityEngine_Vector3(unpack(endPos))-UnityEngine_Vector3(unpack(position)))

posx=posx hspeeddir.xdeltatime posy=posy vSpeeddeltatimevelocityY velocityY=velocityY-10deltatimevSpeed SetLocalPosition(posx,posy,0)

0 人点赞