I need to develop a VR game for an assignment, but I’ve encountered an issue. I’ve written code to handle the interaction between a thrown baseball and the player’s bat, but the collision code I implemented doesn’t seem to be working correctly. Ideally, when the baseball is thrown, I want it to bounce off the bat. However, the current implementation allows the baseball to pass through the bat and orbit the duck (catcher). How can I modify the code to ensure that the baseball collides with the bat and reflects in the direction the bat is facing? Additionally, if the player fails to hit the baseball, I want the game to notify them that it’s strike 1. heres the game link, CoSpaces Edu :: baseball game
Collision events are like click events and key events. You can only declare them once. Any later declaration will overwrite the previous declaration.
In the case that you want to check when an object collides a number of objects, you will need to use the Collides with anotherItem block, and use if statements to work out which object it has collided with.
Something like this:
Edit: I also notice that the ball is traveling quite fast and isn’t very large. If you fix the code and it’s still not colliding, you might want to slow down that ball. Also, don’t forget to enable physics. It’s quite good for things like a modeling bat and ball.
for some reason, the ball is still circling the duck. i slowed down the ball, made it bigger, and added physics, but nothing works. maybe its something in my code? sorry for the trouble.
okay, it kind of worked. now, even if the baseball does not collide with the bat, it still either goes to the t-rex or the cuboid. in simple form, the baseball does not reach either the bat or the duck, but it would still fly.
thank you for the help,
Edit: i updated the game
I can’t look now but will tomorrow if I get time. I still have Co-Spaces for now, but it will expire soon, but I’ll be back if our teachers decide to run the same curriculum again.
Depending on your year level and the expectations of your teacher, I wouldn’t freak out too much if you can’t get it working properly by the due date.
Keep doing what you’re doing. You’re trying and you’re learning, and you’ve reached out to the community! These are all good things.
Might be worth talking to your teacher to see if all this can be taken into consideration when being marked.
if there’s anything specific you’d think will work well in the code, you can reply. I appreciate your assistance and am grateful for your willingness to help. Whenever you have the opportunity to look over the code, I’ll be ready to put any feedback or suggestions you may have. Thanks again for your support.
have a great day/ night,