It looks like you're new here. If you want to get involved, click one of these buttons!
I made a soccer game and added some "on trigger colliders".
Made the ball reset it's position to the middle of the field when scoring,but the speed that the ball had when entering the goal post still applies to the ball when reseted(so when i score the ball is still flying when i reset it to the middle.)
Also is my first game ,new to programming :)
You're close with that.
The error you're getting is because you removed the 'void' when you renamed the OnTriggerEnter method, which you should keep, we just want to move the code in there to a NEW method so it's easier to manage.
// Edit: Fixed formatting =p
void OnTriggerEnter(Collider col) { if(col.CompareTag("goal")) { ResetBall(); } } void ResetBall() { Rigidbody rb = GetComponent<Rigidbody>(); rb.velocity = Vector3.zero; transform.position = startingPosition; }
Answers
Hi @Spartan,
That sounds like a velocity issue, are you using a Rigidbody for this?
Can you post some code? We can help more with code to review.
Thanks,
Slug
,This is the code,i want the ball to reset it s speed too.
i ll try and add the scoring system by myself later <#
Can you post the code that moves the ball too?
All you need to to is set the velocity to 0, but we need to see where the velocity is set to begin with.
Edit: Just remembered that this is a ball, not receiving direct input, my B.
GetComponent<Rigidbody>().velocity = Vector3.zero;
I m verry new to unity and c# i don t understand,could you give me photo/text with the corrected things ?
I m more used to c++ but idk if unreal is good for begginers
Also i get an error "Method must have a return type"