Making a grabby grabber

Well, first we’re going to use raycasts to find the object in the scene, like Ben said. That right there will get us the object we want to move around, since when the raycast hits something it’ll give us a reference to what it hit. (I think, I can’t imagine it not doing that)

Since it doesn’t look like we’ll be writing any input code for this (from the demo in the video), we’ll probably check the distance of the raycast first. If it’s less than a “grab distance” or something that’ll be editable through a UPROPERTY, and it’s also a grabbable object, then we pick it up and start moving it with the player.

To do the actual moving I think we’re probably going to parent it to either the camera or the pawn, but somehow we need to make it ignore backwards movement so that we can let go of it. Maybe we parent it by a camera boom that can change it’s length? idk, I think I remember doing something like that last time I played with Unreal.

Deciding which objects are grabbable is a more difficult issue, I’m not quite sure how we do that. Maybe have a component on the chair that’s just there as a marker and doesn’t do anything? Then when we collide with things we can check for that component to differentiate things like the floor from things like chairs. If Unreal has a tagging system like Unity does then it gets easy, we just tag things as “grabbable”. In this case though, a tag probably doesn’t have any benifit over a marking component, except for maybe performance? Tags really shine when you need to get all the things of a certain type from the scene, like “get all enemies and tell them the alarm’s been sounded”, in this case where we already have the object and we just want to know a property of it, tags or marking components would probably be equally as easy.

I would definitely make the grabber a component. We “have” the ability to grab things, we aren’t a grabber. In general, anywhere I could use a component over inheritance I do, since components can be much easier to reuse if you keep it in mind while writing them. They have a lot less coupling to the pawn, I don’t have to make other things members of a “Grabber” class just to grab things. Say I did the same thing for jumping and made it a member of a “Jumper” class, now if I want to grab AND jump I need to untangle the mess of multiple inheritance or duplicate the code manually. But if they’re just components, then I can just put a jump component and a grab component on one object no problem.

Privacy & Terms