How would I go by redirecting momentum and reducing it?

an example
How to go about it would vary on whether you want to take verticality into account and whatever do you mean to do by "reducing" it.

Here's how it would look like if it were strictly horizontal and if I wanted to reduce speed by like 25%:

dog:
-- Assuming variable mo holds a mobj_t
-- First get the horizontal momentum of mo,
-- reduce the momentum by some factor,
-- and then P_InstaThrust mo somewhere else.

-- A) Getting current speed
-- FixedHypot(fixed_t a, fixed_t b)
local speed = FixedHypot(mo.momx, mo.momy)
-- Assuming a right triangle where mo.momx and mo.momy are two of the sides,
-- FixedHypot gets the remaining side. This is the actual speed.
-- We COULD get the angle of this speed, but we don't need it for this.

-- B) Reducing speed
-- You didn't really elaborate what do you mean by "reduce".
-- Here's how I would multiply momentum by 0.75 to reduce 25% of the speed.
speed = FixedMul($, FRACUNIT/4*3)
-- $ represents "the variable being assigned to". In this case, "$" represents the variable "speed".
-- Remember SRB2 Lua does not support decimal numbers. Think of a FRACUNIT as having a value of 1:
-- 1 / 4 = 0.25
-- 0.25 * 3 = 0.75

-- C) Thrusting object
-- P_InstaThrust(mobj_t mobj, angle_t angle, fixed_t move)
P_InstaThrust(mo, mo.angle, speed)
-- This thrusts a mobj towards an angle at a specific move speed.
-- For angle, I picked the object's current angle,
-- and for move speed, I chose the current sped. Hence, redirection!

-- That's it lol
 
Last edited:

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top