Calculating A_Recoil distances?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
TDRR
Posts: 815
Joined: Sun Mar 11, 2018 4:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Debian 12/ Manjaro
Graphics Processor: nVidia with Vulkan support
Location: Venezuela

Calculating A_Recoil distances?

Post by TDRR »

I'm trying to make an actor travel in a straight line 134 units in a single step, and because A_Chase doesn't really allow me to do this (the thing keeps turning and doesn't allow me to control when to make an actor turn) i thought about using A_Recoil.

A_Recoil starts "teleporting" you forward at higher values (10 or more is when it becomes ever so slightly noticeable) so i can use A_Stop 1 tic after to stop at exactly the teleported position and execute anything i want at that moment, like spawning something for example.

But, does A_Recoil have any formula for calculating the very first tic of movement in map pixels?
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Calculating A_Recoil distances?

Post by Arctangent »

A_Recoil just adds velocity to an actor's current velocity, with no sort of addition calculation. So if you want to move an actor backwards by x in a zero friction environment, you call A_Recoil(x).

The key words being zero friction environment. Velocity-based movement in ZDoom occurs in several steps per tic ( because otherwise things would just run through walls when going fast enough ) and friction is checked for each of them. So while you could calculate the necessary velocity required to move 134 units in places where the friction will remain constant throughout every step, the moment the actor gets itself in a situation where the friction isn't constant? It isn't moving exactly 134 units.

This isn't a highly what-if situation, either: the moment an actor starts or stop touching the ground, its friction changes. So doing this via velocity movement breaks as soon as the actor isn't on perfectly flat ground that has a constant friction value throughout it.

[wiki]A_Warp[/wiki] completely skips all these factors and just moves the actor, no ifs or buts about it. As a bonus, it also doesn't screw with the actor's velocity any.
User avatar
TDRR
Posts: 815
Joined: Sun Mar 11, 2018 4:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Debian 12/ Manjaro
Graphics Processor: nVidia with Vulkan support
Location: Venezuela

Re: Calculating A_Recoil distances?

Post by TDRR »

Arctangent wrote:A_Recoil just adds velocity to an actor's current velocity, with no sort of addition calculation. So if you want to move an actor backwards by x in a zero friction environment, you call A_Recoil(x).

The key words being zero friction environment. Velocity-based movement in ZDoom occurs in several steps per tic ( because otherwise things would just run through walls when going fast enough ) and friction is checked for each of them. So while you could calculate the necessary velocity required to move 134 units in places where the friction will remain constant throughout every step, the moment the actor gets itself in a situation where the friction isn't constant? It isn't moving exactly 134 units.

This isn't a highly what-if situation, either: the moment an actor starts or stop touching the ground, its friction changes. So doing this via velocity movement breaks as soon as the actor isn't on perfectly flat ground that has a constant friction value throughout it.

[wiki]A_Warp[/wiki] completely skips all these factors and just moves the actor, no ifs or buts about it. As a bonus, it also doesn't screw with the actor's velocity any.
So, i could just make it spawn 10 units over the floor with a +NOGRAVITY flag and that should be enough to achieve zero friction?

Does contact with a ceiling count as friction?
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Calculating A_Recoil distances?

Post by Apeirogon »

You really need to start use a zscript, especially for purpose like this.
Because it provide much more controls over actor and it movement, so you dont need to create hacks to achieve desired result.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Calculating A_Recoil distances?

Post by Arctangent »

TDRR wrote:So, i could just make it spawn 10 units over the floor with a +NOGRAVITY flag and that should be enough to achieve zero friction?
No, as there's air friction. Not to mention that any >9 height bumps in the floor will throw off your calculations.

If A_Warp isn't an option because of your engine or whatever, then what you're trying to accomplish is just exceedingly impractical in that engine and probably isn't worth doing in it in the first place.
User avatar
TDRR
Posts: 815
Joined: Sun Mar 11, 2018 4:15 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Debian 12/ Manjaro
Graphics Processor: nVidia with Vulkan support
Location: Venezuela

Re: Calculating A_Recoil distances?

Post by TDRR »

Arctangent wrote:
TDRR wrote:So, i could just make it spawn 10 units over the floor with a +NOGRAVITY flag and that should be enough to achieve zero friction?
No, as there's air friction. Not to mention that any >9 height bumps in the floor will throw off your calculations.

If A_Warp isn't an option because of your engine or whatever, then what you're trying to accomplish is just exceedingly impractical in that engine and probably isn't worth doing in it in the first place.
Depends, does A_Warp work online in Zandro? I would try myself, but i can't without anyone else to test.

I probably won't be using ZScript any time soon because every and all of my projects are built for Zandronum and GZDoom 1.8.6/ZDoom 2.8.1.

EDIT: Nevermind, i used A_Warp in Zandro before like a couple million times and it works well so i will use that. Thanks for the advice Arctangent!

EDIT2: But how would i warp without a target?
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Calculating A_Recoil distances?

Post by Arctangent »

An actor can point to itself.
Post Reply

Return to “Scripting”