- Home /
Question by
blackmask86 · Dec 05, 2020 at 09:16 AM ·
gameobjectraycasttransform.positionlayermask
Move up gameobject from under the ground or object (vibration problem)
Hello , i have a script for align to coin from ground or some objects..
Here is a code ;
public class raycast2 : MonoBehaviour
{
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, -Vector3.up, out hit))
{
}
if (hit.distance <= 2.0f)
{
rb.velocity = transform.up * 150 * Time.deltaTime;
}
else if (hit.distance >= 2.0f)
{
rb.velocity = -transform.up * 150 * Time.deltaTime;
}
}
}
I instantiate objects that sometimes moving.. Also different in height. When objects are in motion, they have to lift it up instead of passing through gold. After the object comes out from under it, it must return to its old place according to the height of the ground.
Comment
Your answer
Follow this Question
Related Questions
How to develop a script that substitute a gameobject position with my character? 0 Answers
Substituting between two gameobjects transform position 1 Answer
How to make my raycast also hit deactive objects WITHOUT showing the object? 1 Answer
Adding rotation to Physics.AddForce(); ... Getting weird error? 0 Answers
Raycast Get Object Using Empty GameObjects in Hierarchy 0 Answers