Hi, is there any tutorials on how to program collisions? I can do it easily in BP, however i’d like to as much as possible in code, just to hone my skills. If there are no tutorials at the moment, would someone like to give me a quick run through? I have tried to do it before, but ended up with loads of breakpoints which i couldn’t fix.
I want to trigger an event when player collides with collidePlate
The Engine’s physics simulation should calculate most of the collisions for you, in both blueprints and code (Such as ActorGetDistanceToCollision method). However, a basic approach to collisions can be done with a sphere-to-sphere method.
You will need each of your objects positions and a radius in which to calculate whether a collision happens when the radius of each object intersects.
It would look something like:
FVector objAPos = ;//Get objects location
FVector objBPos = ;//Get objects location
if (FVector::Dist(objAPos, objBPos) < someRadius)
{
// You have a collision
}
Obviously that is the most naive approach to solving this problem but it gives you a basic idea of collisions.
Yes it is. A blueprint callable overlap event would look like;
UFUNCTION(BlueprintCallable, Category = Interaction)
void OnBeginOverlap(AActor* Other, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
In the header file. If you do the intro programming tutorials there’s a collection component as part of the character, with overlap events etc in C++. Its not exactly the same as what you’re asking, but the practice would help you use the docs better…
There’s some information here on overlapping events. You can also call overlap functions such as GetOverlappingActors/Components from any actor class as well.
Well, if your collider plate doesn’t have a collision volume, maybe just call onactorhit, on the mesh? Have you made a class, or a blueprint, for your collision plate? or is this a single instance of a brush or something? If it’s a single instance of an object, select it in the editor, look down the right hand side details panel and click “add level events for…”
I think if you’ve got no experience at all in programming, it may be a good idea to have some other assistance too. Maybe a course or a book? I’m also doing it on my own- I did the Stanford uni CS106A and CS106B, online. I get pretty lost as it is, but if I hadn’t done that it would be frying my head completely. Take a look at those (if they are still available) and also books like “Thinking in C++” by Bruce Eckell. I’m not being snooty, I promise. Even just the intro to Thinking in C++ would explain why I was asking if its a single instance or if you’ve made a class…
I’ve been programming on and off for around 2 years, i wouldn’t exactly say i have ‘no experience at all’. It’s just the way Unreal is structured puzzles me at times, where logically code should work but it just doesn’t ;/ And no offense taken, i know you’re just trying to help. I switched the code around, and fixed something. Will show you when i get back
When I say fix something I did it in code. Using delegates and signatures and all this good stuff. But now I’ve got another problem. Code works on a capsule component with a mesh attached in the bp editor but not on a box component with a static mesh attached in code. Will be easier to show you when I return
EDIT: Upon reviewing the question, i’ve found that the title is misleading, i was asking how to fire events, which i now know how to do.
“Well, if your collider plate doesn’t have a collision volume, maybe just call onactorhit, on the mesh? Have you made a class, or a blueprint, for your collision plate? or is this a single instance of a brush or something? If it’s a single instance of an object, select it in the editor, look down the right hand side details panel and click “add level events for…””
I’m going to try and call OnActorHit on the mesh when i get back in, that was one of my potential fixes but i didn’t get a chance to try it. The collision plate is a component attatched to my CoinBrick class. Which i have created a blueprint from.