mirror of
https://github.com/ElCeejo/creatura.git
synced 2025-03-21 15:21:24 +00:00
Improved Velocity Handling
This commit is contained in:
parent
8fc703b6f7
commit
b41508c8dd
1 changed files with 19 additions and 4 deletions
23
mob_meta.lua
23
mob_meta.lua
|
@ -192,22 +192,37 @@ end
|
||||||
-- Sets Velocity to desired speed in mobs current look direction
|
-- Sets Velocity to desired speed in mobs current look direction
|
||||||
|
|
||||||
function mob:set_forward_velocity(speed)
|
function mob:set_forward_velocity(speed)
|
||||||
self._movement_data.horz_vel = speed
|
if self.step_delay then
|
||||||
|
self._movement_data.horz_vel = speed
|
||||||
|
else
|
||||||
|
local yaw = self.object:get_yaw()
|
||||||
|
local vel = self.object:get_velocity()
|
||||||
|
vel.x = sin(yaw) * -speed
|
||||||
|
vel.z = cos(yaw) * speed
|
||||||
|
self.object:set_velocity(vel)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Sets Velocity on y axis
|
-- Sets Velocity on y axis
|
||||||
|
|
||||||
function mob:set_vertical_velocity(speed)
|
function mob:set_vertical_velocity(speed)
|
||||||
self._movement_data.vert_vel = speed
|
if self.step_delay then
|
||||||
|
self._movement_data.vert_vel = speed
|
||||||
|
else
|
||||||
|
local vel = self.object:get_velocity()
|
||||||
|
vel.y = speed
|
||||||
|
self.object:set_velocity(vel)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function mob:do_velocity()
|
function mob:do_velocity()
|
||||||
|
if not self.step_delay then return end
|
||||||
local data = self._movement_data or {}
|
local data = self._movement_data or {}
|
||||||
local vel = self.object:get_velocity()
|
local vel = self.object:get_velocity()
|
||||||
local yaw = self.object:get_yaw()
|
local yaw = self.object:get_yaw()
|
||||||
if not yaw then return end
|
if not yaw then return end
|
||||||
local horz_vel = data.horz_vel or (data.gravity == 0 and 0)
|
local horz_vel = data.horz_vel or (data.gravity >= 0 and 0)
|
||||||
local vert_vel = data.vert_vel or (data.gravity == 0 and 0)
|
local vert_vel = data.vert_vel or (data.gravity >= 0 and 0)
|
||||||
vel.x = (horz_vel and (sin(yaw) * -horz_vel)) or vel.x
|
vel.x = (horz_vel and (sin(yaw) * -horz_vel)) or vel.x
|
||||||
vel.y = vert_vel or vel.y
|
vel.y = vert_vel or vel.y
|
||||||
vel.z = (horz_vel and (cos(yaw) * horz_vel)) or vel.z
|
vel.z = (horz_vel and (cos(yaw) * horz_vel)) or vel.z
|
||||||
|
|
Loading…
Add table
Reference in a new issue