x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

TWO PLAYER TOP DOWN - STOP PLAYERS RUNNING OFF SCREEN

Hi all.

I'm currently creating a two player top down shooter. Both players play on the same screen and I've set up a camera to always follow the mid point of the players. Unfortunately, I can't figure out a way to stop the players running off screen. I've tried setting up collision boxes in the camera blueprint, which isn't ideal, stopping player movement when a set distance from the other - but also not ideal as the player always needs to be able to move (still allowing them to run back toward the centre of screen).

Is there a way to invert the collision sphere? Seems like that would be perfect to slap into the camera blueprint.

Any other solutions anyone has?

Cheers!

Product Version: Not Selected
Tags:
more ▼

asked Feb 25 '15 at 10:24 AM in Blueprint Scripting

avatar image

RJBryan
1 1 2 2

avatar image IanBreeg Feb 25 '15 at 10:27 AM

You can just limit their position in world space. Meaning, when you update their movement you check if their global position is in the bounds you've set up and if not - do not update their position this tick.

avatar image RJBryan Feb 25 '15 at 10:32 AM

Thanks for the quick reply! Sounds simple enough - would you mind elaborating on how this can be achieved in blueprints? Thanks!

avatar image IanBreeg Feb 25 '15 at 10:55 AM

Upon reading your question again I've realized that I might've interpreted it wrong. Do you mean a map-boundaries? Like the end of the level or just the camera viewport boundaries?

avatar image RJBryan Feb 25 '15 at 11:00 AM

Viewport boundary. So both characters are always on screen - like Diablo III on consoles. The camera is always a fixed height on a spring arm, so the view is consistent throughout - it just focuses on the mid point of the vector between the two players.

avatar image IanBreeg Feb 25 '15 at 11:26 AM

Then its a little bit trickier. It will involve some vector math.

alt text

You need to calculate your viewport size using your field of view value which you can get from your camera component in blueprints. Then, you will need to construct your viewport boundaries using your camera anchor point and its dimensions. This will basicaly give you a plane of some size (x, y). In general, you will need to make sure that your player's position realtive to the anchor point (the center of the plane) is always inside of that plane (abs(Player.X) - abs(Camera.X) < Camera.MaxX and same for Y).

alt text

It's not the easiest thing to implement, but absolutely doable. Tell me if you need more info.

1.png (7.1 kB)
avatar image RJBryan Mar 04 '15 at 02:34 PM

Thanks for that dude. I totally get what you're saying, but I've had no luck implementing it into blueprints unfortunately. Any sort of simple breakdown you could give would be much appreciated.

avatar image Mortusnyte Mar 08 '15 at 01:54 AM

Wouldn't it be easier to attach two Collision components(box) to the Camera component. These invisible walls will always follow the camera. To position them accordingly to Viewport size just Get Viewport Size node / 2 = X. One wall will be at Camera location(x-axis) - X and the other Camera Location(x-axis) + X. Maybe I'll test it out later for you.

You could set these walls to only block the players and nothing else.

Oh I was thinking of a 2d side scroller, my bad :P Well I think It could still work though you would add two more walls on the y axis.

avatar image RJBryan Mar 08 '15 at 09:10 AM

Tried using four collision boxes in the camera component, but not to any great effect. I didn't use the viewport size node, though. Worth a shot! Thanks.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

You could have your camera zoom in and out dependent on the distance between the players (smooth average between the two) and then limit the distance they can be apart from each other by measuring the difference in distance and giving a branch if greater than distance then movement wouldn't work?

more ▼

answered Feb 25 '15 at 12:01 PM

avatar image

jestersheepy
489 16 22 27

avatar image RJBryan Mar 08 '15 at 09:11 AM

This was the first approach I took to it (without the zooming functionality), but then there was the issue of enabling the player controllers after disabling them.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Is it possible to attach the NavMesh to the camera and make it the same size as the field of view, so that the players cannot move out of it?

more ▼

answered Mar 08 '15 at 12:48 AM

avatar image

Busymonkey
25 4 4 9

avatar image RJBryan Mar 08 '15 at 09:07 AM

Isn't a NavMesh used for AI pawns to pathfind around a level? Have you used it for playable characters at all?

avatar image Busymonkey Mar 08 '15 at 10:12 PM

NavMesh is a necessity in Top Down gamemode. There's a NavMesh in the template when you start a new project and the player won't move without it.

However, now that you're questioning this and I assume you've already seen the players run out of the cameras viewport, I don't know what to tell you <.<

avatar image RJBryan Mar 08 '15 at 10:43 PM

I'm not sure how that's set up then to be honest - although the topdown template does have one, I've built this project from scratch without a navmesh. Both players can move freely without one (collision with geometry the only thing to restrict a players movement).

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question