|
| 10 Oct 2017 01:08 AM |
I'm making a script that takes a player's mouse input and allows the player to click on a part and move it around and when the player lets go, it falls. I'm using BodyPosition to move it around, and I've gotten it mostly figured out. I have a method that works well in first person, but I'm trying to get something that works for both first person and 3rd person.
Here's my equation for getting the position: object.BodyPosition.Position = player.Character.Head.Position+mouse.Origin.lookVector*d
In this case, d is the distance taken initially between the player's head and the object. This is meant to keep the object at a set distance away from the player while it is being moved. Right now, this works really well in first person, in fact perfectly. This is because the camera is the same location as the head of the player. However, zoom out, and the object's movements are different. Anyone got any good ideas to fix this? |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 10 Oct 2017 01:22 AM |
mouse.Origin.lookVector Why use this line? This is the coorelation between movement and camera.
You either need to figure out a way to do it without involving the camera or force the player to be locked into first person when they are using this mechanic.
Last option would be to have a separate equation for when you zoom out, but I think that would get chaotic fast. |
|
|
| Report Abuse |
|
|
|
| 10 Oct 2017 01:25 AM |
I came up with this: it works alright, I'm sure someone brighter than I can come up with one better.
local newFrame=CFrame.new(player.Character.Head.Position, mouse.Hit.p) --Creates a "Ray" from the head of the character to the mouse location object.BodyPosition.Position = player.Character.Head.Position+newFrame.lookVector*d --This works fairly well in both 3rd and first person |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 10 Oct 2017 01:25 AM |
object.BodyPosition.Position = player.Character.Head.Position+mouse.Hit*d
can't promise this will work |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 10 Oct 2017 01:27 AM |
| Are you using LookVector so that you can multiply by d? |
|
|
| Report Abuse |
|
|
|
| 10 Oct 2017 01:43 AM |
| yes, it sets the distance away from the character. |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 10 Oct 2017 01:48 AM |
Maybe instead do something like this?
object.BodyPosition.Position = player.Character.Head.Position+mouse.Hit
repeat if (object.BodyPosition.Position - player.Character.Head.Position).Magnitude < 50 -- or so then object.BodyPosition.Position = object.BodyPosition.Position + Vector3.new(10, 0, 0) until mag >= 50
Only issue would be that the object will always be pushed to one side of the character if you get too close. May be annoying, but definitely editable. |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 10 Oct 2017 01:49 AM |
| Or you could set up a LookVector that is always set to the character's position instead of setting it to the camera, this way it will always be based off of the total zoomed in factor rather than any given camera zoom. I'm not sure how to implement this. |
|
|
| Report Abuse |
|
|
|
| 10 Oct 2017 01:52 AM |
| I'm not asking how to do it, I've already done it. I'm asking if anyone has something more clever... the part works smoothly and it works correctly in 3rd and 1st person with and even while zooming in and out. That's not really the question. I'm just asking if anyone has anything they've done that is better. |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 10 Oct 2017 01:54 AM |
| Alright, well I hope I contributed in some way. Sorry if I was more annoying than helpful. |
|
|
| Report Abuse |
|
|
|
| 10 Oct 2017 02:05 AM |
| You're alright, thanks for the input regardless, I know you were just trying to be helpful |
|
|
| Report Abuse |
|
|
|
| 10 Oct 2017 02:11 AM |
| Maybe you can assist me with a new issue: I'm trying to make the block rotate from the camera's point of view. So if the camera is looking towards the block, W is up, S is down, A is left, and D is right as far as rotation goes. I don't want to rotate the block by its coordinates, I want to rotate it according to the camera's point of view. Any ideas? I'm currently on the drawing board trying to write it out. |
|
|
| Report Abuse |
|
|
|
| 10 Oct 2017 08:26 AM |
| Bump - good morning scripters! |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 10 Oct 2017 11:33 AM |
object.CFrame = CFrame.new(object.Position, cam.CFrame.LookVector)
This would make the object face the same direction you face I believe..?
|
|
|
| Report Abuse |
|
|
|
| 10 Oct 2017 11:39 AM |
| That would error out because you're using two different data types but still not quite the idea. I'm trying to rotate the block relative to the camera's angle. So no matter which direction you look at the block if you want to rotate it, up will always be towards the top of your screen. |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 10 Oct 2017 11:45 AM |
I don't know, this is relatively complicated.
Although, what do you mean that it would error because it's two different data type? |
|
|
| Report Abuse |
|
|
|
| 10 Oct 2017 12:08 PM |
| You were using a position and a lookVector, one is a direction and the other is a Vector3 position |
|
|
| Report Abuse |
|
|