PlaceholderGames / 2122-yr1-team-cookieshot

CS1S464 2021/22 Team Cookieshot
0 stars 0 forks source link

How do I set the sprite in unreal engine to automatically move to one direction? #2

Closed KWHMarco closed 2 years ago

KWHMarco commented 2 years ago

@DoctorMikeReddy I wanted set the sprite to only move right and players cannot move it

DoctorMikeReddy commented 2 years ago

I need more information. What is the sprite? What code should I look at? What is the desired behaviour?

You should initially look at waypoints of it is an NPC. If it is an obstacle, bullet, etc, then it will need a blueprint for the sprite. Have a look at the top down 2D shooter tutorial

KWHMarco commented 2 years ago

ok, will fill in the details later i am having lunch right now

KWHMarco commented 2 years ago

the sprite is player character, as for the code i am not sure where to chack is it the sprite blueprint? The desired behaviour is to set a humanoid that automatically walk to right and the players can't control it as our game main objective is to prevent it falling off the map

KWHMarco commented 2 years ago

For clarification, our game is quite similar to a game called lemmings where we have to safely transport them to the exit and we have to use tools to help them stay alive

DoctorMikeReddy commented 2 years ago

Ok, then it’s not a player character (because you can’t control it). The player character is non-existent, or the mouse, of that’s how you’re controlling the game. I’ll look at this tomorrow, and will make you some sample code in a branch

DoctorMikeReddy commented 2 years ago

Do you have any code? Or a template/tutorial project that you are going to base your game off?

KWHMarco commented 2 years ago

For the tutorial project, I am using a 2D side scroller which is provided by unreal engine at the start

DoctorMikeReddy commented 2 years ago

Can you confirm which one? That way I can create code for you. Guessing you want them to die if they fall too far?

On 14 Oct 2021, at 17:00, KWHMarco @.***> wrote:

 For the tutorial project, I am using a 2D side scroller which is provided by unreal engine at the start

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

KWHMarco commented 2 years ago

the name is 2D side Scroller Template,and yes I do want them to die when they fall off screen

KWHMarco commented 2 years ago

@DoctorMikeReddy sorry mike i still have trouble to get my ai to move.

DoctorMikeReddy commented 2 years ago

Working on this now. I will upload the side scroller that you referenced, then create a branch that spawns and has characters moving right (to their doom).

KWHMarco commented 2 years ago

thanks man

DoctorMikeReddy commented 2 years ago

I am going to break down creating Lemmings style characters that spawn and run to the right, before dying horribly. I will do this on a branch called 'lemming' that is now up on the server, based on the 2D side scroller that you said you were working with. I will have to do it in a number of steps: 1) (eventually) remove the player character - initially, I will just disable the controls, and use some of them for iterative testing 2) I will create a spawn actor (and Blueprint) to create a new character when I hit UP arrow, as we won't need the jump key 3) I will then create a 'kill box' for it to "die" if it hits 4) I will then add to the character's script to make it move to the right; this will use code from the original player controller, but without using player input 5) I will add the ability for the character to stop if it hits an obstacle, such as a block or another character

Firstly, we disable the existing player control for jumping: image We will leave the rest intact for now, so we can move around the level with the original player character. image will just print a temporary text message to the screen. image

Now we need to spawn a new character, based on the player character...

KWHMarco commented 2 years ago

For the "kill box"is it something involve "box trigger" to make a invisible killing zone

KWHMarco commented 2 years ago

there is few more issues: I can only get one sprite to move right(even when I duplicate them) When the first sprite dies the camera angle changes

DoctorMikeReddy commented 2 years ago

OK, firstly we need to create a LemmingAI folder and copy the 2DSideScrollerCharacter into this folder, renaming it LemmingAI: CopyPlayerBP Then we need to be in this folder and create a new AIController Blueprint (by right clicking in the folder view and choosing Blueprint Class, calling it LemmingAIController: NewBP AIController

We also need to remove the camera from the new LemmingAI object: RemoveCamera and adding the AIController: AddAIController Some editing of the LemmingAI event graph is needed to remove player control and to run animations. We also add the code hack here of making the Lemming run towards the player character; a separate goal will be needed eventually, but for now this is good enough. NOTE: there is currently a small bug that prevents the animation from running left, even if the character can go there if you jump over them and run to the left. I've started to look at a variable to tell it which direction it should face, but it isn't working yet: ChangeDirectionVariable SetDirectionVariable

DoctorMikeReddy commented 2 years ago

Code is on lemming branch. I need to fix the animation bug, and then create an AI Spawner to spit out Lemmings, rather than placing them manually in the level

DoctorMikeReddy commented 2 years ago

In order to get the Lemming to follow the player, we need the Lemming X location (as this is Paper2D, X is horizontal): LemmingXlocation and we need the player's X coordinate too: PlayerXlocation So, we can then change the Lemming movement direction, etc, using these values: ChangeLemmingDirection

DoctorMikeReddy commented 2 years ago

Above had the bug. Fixed now. Here is the simplified movement and animation code SimplifiedMovementFix :

DoctorMikeReddy commented 2 years ago

So, we have a manually placed AI sprite, which currently attempts to follow the player. For a lemming, it should just go right until it cannot go any further. A simple hack would be to replace the code that compares the locations of the Player and the lemming with something that just made it move right. However, I am not sure what exactly is wanted from the character. So, I will attempt now to add a spawner to create multiple copies instead. This has been added now, by choosing the Actor Blueprint type, and renaming AISpawnLemming: AISpawnActor Then adding the following code: AISpawnerCode And a Box Collision object in the Viewport: AISpawnerViewportBoxCollisionNode

DoctorMikeReddy commented 2 years ago

All adapted from the following tutorials, with heavy modification: https://www.youtube.com/watch?v=G2JDYz7dxbg https://www.youtube.com/watch?v=q2enLa6T5qU <- This one is especially good!!! https://www.youtube.com/watch?v=L2mpvThlxzM

DoctorMikeReddy commented 2 years ago

Tell me if you need any more here