Thanks for posting this.
I’m currently applying a “magic number” force and it these seem to function somewhat… but I can’t seem to get it to produce the right behavior yet.
When the game first loads and I try launching the object at a 45 degree angle… it works as planned. But then if I adjust the angle or move the player about the level, it all gets out of whack and nothing behaves as expected.
Here’s what I’m doing in my player object:
if message_id == hash("animation_done") then
if (message.id == anim_fall_throw) or (message.id == anim_stand_throw) then
-- if message table anim id is a throwing anim then create stone
local pos = go.get_position("player")
if self.holding_stone then
print('Anim complete, now throwing stone')
msg.post("#holding_stone", "disable")
msg.post("trajectory", "disable")
-- Calc throw
local x_force = math.cos(self.traj_angle) * throw_force
local y_force = math.sin(self.traj_angle) * throw_force
print(x_force .. ' ' .. y_force)
local stone = factory.create("#stone_factory", vmath.vector3(pos.x + 20, pos.y + 64, .9), nil, { direction = self.direction }, 1)
msg.post(stone, "apply_force", { force = vmath.vector3(x_force, y_force, 0), position = go.get_world_position("#player") })
--msg.post(":level/stone_controller#script", "throw_stone", { player = 1, id = stone })
self.holding_stone = false
end
-- resume prev animation after throw
msg.post("#sprite", "play_animation", {id = self.anim})
end
end
Here’s an example of the behavior.
Anything you can see that is obviously wrong here?