#Alternative to q.movement_direction?

1 messages · Page 1 of 1 (latest)

vocal sphinx
#

I’ve been using this query for my mob with the player runtime identifier since it only works for players, however recently in 1.20 this has stopped working.

Is there any other way I can get this query to work on non-player entities, and if not what other alternatives are there?

My goal is to rotate a mob to face the direction it’s moving in

astral saddle
#

I believe movement_direction only works for cardinal directions

You can instead use position_delta and some trig to get a heading angle:
v.heading_horizontal = math.atan2(-q.position_delta(0), q.position_delta(2)) + 180
This one uses x-axis and z-axis speeds to find the horizontal movement angle and ranges from 0 to 360

vocal sphinx
astral saddle
#

I know it works on players, but maybe not on entites
Could there be an error somewhere?

vocal sphinx
#

dont believe so

#

is there a way i could manually calculate the position delta or movement direction

inland sable
#

@vocal sphinx
Hi, did you get anywhere on getting this to work? Running into the same problem.

carmine creek
#

You can calculate position delta manually, position delta is just current position minus previous

vocal sphinx
#

yeah i had a system to manually calculate the position delta, but the rest of the code i had didn’t seem to work (i’m not sure if it’s the rest of the codes fault or a difference between position delta and movement direction)

#

i wasn’t sure if there was a difference between position delta and movement direction but as far as i know the only difference is movement direction is normalised

#

so i am currently still stuck sorry @inland sable, but you can try manually calculating the position delta and see if that fixes your issue

vocal sphinx
#

okay yeah i did end up getting it working just manually calculating the position delta

#
"v.position_z_delta = v.position_z != q.position(2) ? q.position(2) - v.position_z : v.position_z_delta;,

"v.position_x = q.position(0);",
"v.position_z = q.position(2);",```
carmine creek
#

If it's on the client, you should only calculate delta when position changes btw, since it happens every tick not every frame

vocal sphinx
#

good spot, fixed 👍

inland sable
vocal sphinx
#

should do, worked fine for me

inland sable
#

Got it working 😎

vocal sphinx
#

awesome sauce

final gull
#

@vocal sphinx How you did it? For some reason my values of deltas don't update

#
"initialize": [
    "variable.delta_x_pos = 0;",
    "variable.delta_z_pos = 0;",
    "variable.position_x = q.position(0);",
    "variable.position_z = q.position(2);"
],
"pre_animation": [
    "variable.max_fuel = 300;", // max fuel for truck
    "variable.fuel_ratio = query.property('nubs:remaining_fuel')/v.max_fuel;",
    "variable.engine_on = query.property('nubs:engine_on');",
    // coordinates thingy
    "variable.delta_x_pos = v.position_x != q.position(0) ? q.position(0) - v.position_x : variable.delta_x_pos;",
    "variable.delta_z_pos = v.position_z != q.position(2) ? q.position(2) - v.position_z : variable.delta_z_pos;",
    "variable.x_direction = math.sin(q.body_y_rotation) < 0 ? 1 : (math.sin(q.body_y_rotation) > 0 ? -1 : 0);", // 1 if positive, -1 if negative, 0 if none
    "variable.z_direction = (math.cos(q.body_y_rotation) > 0 ? 1 : (math.cos(q.body_y_rotation) < 0 ? -1 : 0));", // 1 if positive, -1 if negative, 0 if none
    "variable.position_x = q.position(0);",
    "variable.position_z = q.position(2);"
],

this is what I have in client entity

vocal sphinx
#

no sure, that looks fine to me

#

either the delta is being updated correctly but you arent seeing it properly, or somehow the position isnt changing every tick

final gull
#

I'll try to mess with it tomorrow

final gull
#

My entity is a car

#

and if there is a player in it

#

I guess I can pull data from a player

final gull
vague cypress
astral saddle
#

I believe the trig functions and headings already output degrees by default, to simplify things