- Home /
raycasting onto an object over time
I working with 1 other and we are trying to ray-cast onto a game object i.e (a grind pole) over a time period of 1 second, were in that second, the ray casting object i.e (board) plays a animation over that second while still moving forward and is at a height of + 1 in y axis or simply on top of the pole collier.
any help would be much obliged
I'm not really sure what you're asking. If you mean that you only want to cast your ray during certain instances then put your raycast into an update loop and activate/deactivate that component depending on whether or not you want to be casting at that moment.
so when the bored hits the pole collider and only the pole collider, the ray-cast detects that object (being the grind rail) and places the bored ontop of pole and plays animation for 1 second then ray-cast stops and fall back to ground level
Answer by iwaldrop · Jan 16, 2013 at 11:22 PM
Well you might give my previous suggestion a shot, and use a script that does a raycast every frame. Use GetHitInfo() to get the hitInfo and turn off the Component when it isn't needed.
using UnityEngine;
using System.Collections;
public class PerFrameRayCast : MonoBehaviour
{
public LayerMask layersToIgnore;
protected RaycastHit hitInfo;
protected Transform tr;
protected int layerMask;
void Awake ()
{
tr = transform;
layerMask = ~layersToIgnore.value;
}
void Update ()
{
Physics.Raycast(tr.position, tr.forward, out hitInfo, Mathf.Infinity, layerMask);
}
public RaycastHit GetHitInfo ()
{
return hitInfo;
}
}
sorry i'm not familiar with c# i should of put that in the comment above, so far our game has bean done in java and when mixing code ive been told things can get tricky
Indeed mixing code can get a bit hairy. Sorry though, I don't really play around with unityscript. There are some advantages to using it, I'm sure, but I'm a c# guy. :)
I would give this a try though. Since all you're doing it turning it on and off and calling the GetHitInfo() method it should play nicely with the rest of your code.
Cool! And if it works then you should mark this question as answered by accepting my answer. Otherwise it'll forever be flagged as unanswered. Thanks, and good luck with your game!
Your answer
Follow this Question
Related Questions
Ray Casting in 2D 1 Answer
Allow y rotation 1 Answer
Time not slowing down on iPhone 3 Answers
Rotatearound Collider axis 1 Answer
Move Parent Along Childs Local Axis 1 Answer