Jump to content

Lua Vector forward


Andy90
 Share

Recommended Posts

2 hours ago, Josh said:

It looks like the Unity "forward" constant is just Vec3(0,0,1). What exactly are you trying to do? Maybe entity.move(0,0,1) is what you are looking for?

Yes the move was what I was looking for. A function to get a vector before the entity would be good, so you could for example spawn something before the character like whats @MarKlilinked

Link to comment
Share on other sites

  • 3 weeks later...

I collaborated with ChatGPT to create a 'lookat' function. While it's not a direct 'forward' function, I believe it can be helpful to others.
 

function LookAt(position, pitch, yaw, distance)
	pitch = math.rad(pitch)
	yaw = math.rad(yaw)

	local forward = Vec3()
	forward.x = math.cos(pitch) * math.sin(yaw)
	forward.y = -math.sin(pitch)
	forward.z = math.cos(pitch) * math.cos(yaw)

	local forward_length = math.sqrt(forward.x ^ 2 + forward.y ^ 2 + forward.z ^ 2)

	forward.x = forward.x / forward_length
	forward.y = forward.y / forward_length
	forward.z = forward.z / forward_length

	forward.x = forward.x * distance + position.x
	forward.y = forward.y * distance + position.y
	forward.z = forward.z * distance + position.z

	return forward
end



 

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...