- Home /
how do i make my cube go down the y axis?
ive been trying to make a destruction effect but the collision doesnt work
this is code:
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
transform.position = new Vector3(0,-5,0);
Debug.Log ("yes");
}
}
help?
note: I'm an amateur at coding
Yes and? What is your issue?
Are you working with 2D physics or 3D physics?
Is
OnTriggerEnter
called?Is the condition evaluated to
true
?Is the
yes
message appearing in the console?What is the current behaviour?
I'm Working With 3d
i just want the cube to fall thru the ground when touched by player
edit: the problem is that the code doesn't work
When you go to your mechanic indicating your car does not work, do you just give him/her a photo of your car? Even if he/she ask questions about what's wrong which could help diagnose the problem? Telling him/her "my car doesn't work" won't help, believe me.
Answer by JustAbhi · Apr 14, 2020 at 04:00 PM
@CutTheChitChat123 so you what you have down is that you have placed the object at position -5 on y-axis.
This is a just a position change which is permanent.If you want to make it fall on the y-axis use this code :-
public Rigidbody obj;
public float speed;
private void OnTrigerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
obj.velocity = new Vector3(0f, speed, 0f);
}
}
Your answer
Follow this Question
Related Questions
Camera Movement Bounds? 1 Answer
Rigidbody Precise Colliders 1 Answer
collider position wrong object position in collider 0 Answers
Collider for transform.position? 1 Answer