- Home /
Raycasting: Holding an Object
This one seems pretty easy, but I can't get my head around it. When casting a ray (on button down) how do you continuously translate an object to the rays position? For example when you move the ray the primitive object will follow the ray's position.
In pseudo-code so far I have:
Create a raycast hit
Create a screen point to ray
If the ray hits an object, on button down, transform the hit.collider position to the hit.point (where the ray hit the object).
Although even though in the Update method this just translates the object to the ray, however I want it continuously translate to this position, until I let go of the button (on button up). Thought about using invoke repeating, a loop or parenting the object, but still can't think of a) a way that works or b) the best way to achieve it (and not just hack it in). Any help lol?
Answer by Majmuns · Jul 03, 2011 at 07:36 PM
Solved this:
Stupidly I was using GetButtonDown, instead of GetButton, so it was just returning the first time the button was pressed, instead of all the frames the button is held down. Don't be as stupid as me, it's bad for your health lol :oD
Your answer
Follow this Question
Related Questions
Picking up rigidbody objects 2 Answers
Problems with raycast 1 Answer
Raycasting to pick up an item problem 1 Answer
[Problem] Cant activate 2D objects with touch? 1 Answer
Problem With Raycast Pickup Using Touch 0 Answers