How to get the side position of a player

Post Reply
LC Creations
Member
Posts: 159
Joined: Mon Feb 18, 2019 02:53
GitHub: LandonAConway

How to get the side position of a player

by LC Creations » Post

I want to get the side position of a player. I know how to get the position in front of them by this calculation...

Code: Select all

local pos = player:get_pos()
local look_dir = player:get_look_dir()
local distance_away = 5

local pos_in_front = {x=pos.x+(look_dir.x*distance),y=pos.y+(look_dir.y*distance),z=pos.z+(look_dir.z*distance)
....But, I want to get the position to the right (x=positive number) or left (x=negative number) of the player 'x' nodes away... NOT in front of the player, but to the side of the player. Im not good at math so I do not know what to do.
cdb_ac3a146dcafb

User avatar
Walker
Member
Posts: 1835
Joined: Tue Oct 03, 2017 09:22
In-game: Walker
Contact:

Re: How to get the side position of a player

by Walker » Post

you need to swap the X,Y and Z variables from distance ...
like

Code: Select all

{x=pos.x+(look_dir.z*distance),y=pos.y,z=pos.z+(look_dir.x*distance)
try also to replace some "+" with some "-"

hint: to transform a vextor by a angle x ... you need to use +/-sin() and +/-cos() ... but if x = 90 ... you only need to swap variables because +/-sin() and +/-cos() are -1, 0 or 1 ... i hope ;)

Lets Try&Error xD

User avatar
Walker
Member
Posts: 1835
Joined: Tue Oct 03, 2017 09:22
In-game: Walker
Contact:

Re: How to get the side position of a player

by Walker » Post

Walker wrote:
Sat Jul 04, 2020 06:40
you need to swap the X,Y and Z variables from distance ...
like

Code: Select all

{x=pos.x+(look_dir.z*distance),y=pos.y,z=pos.z+(look_dir.x*distance)
try also to replace some "+" with some "-"

hint: to transform a vextor by a angle x ... you need to use +/-sin() and +/-cos() ... but if x = 90 ... you only need to swap variables because +/-sin() and +/-cos() are -1, 0 or 1 ... i hope ;)

Lets Try&Error xD
ATTENTION: this works only with 2D !!!
this is the reason why Y stay untouched ... but i hope you dont need to transform Y ... because its only you height

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests