Day 15, Raycast2D + Personal Project update 1
Before today’s PM meeting, I have few challenges in successfully implementing a feature using a Raycast2D. I wasn’t sure whether I wanted to find the target by noting them in a layer or by the tag and if they would be able to be summoned using a mask. The performance I wanted to achieve was to shoot a ray towards down direction detecting whether there’s a player or a pickup and under if statement, when detected, shoot lasers to destroy.
So the point of Raycasting is to point out an invisible/visible laser towards the direction designated to detect an object of collider to implement features such:
Enemy raycast towards the direction down, in case it collides with a player or a powerup pickup, shoot laser prefab and destroy the other.colliding object.
At first, we used Physics2D.Raycast. We need two variable, the position of the current object and the direction. So we used transform.position to get the current position of an object and vector2.down to get the enemy to shoot down. But vector2.down is in unit of 1 so we need to multiply it by the value that we would like the ray to extend to. This completed the scene that I was working on the feature of enemy destroying the pickup when detecting them.
It sounded rather simple in the end, but I am not sure why I had prolonged this problem for the day and struggled to implement the feature I desired. But thanks to the team and our Lead Dan’s help, I was finally able to input and move on.
In the past few days, I’ve been craving something that fits my interest. One game that I used to play for quite a time was Rust, an fps survival game. And I have recently been informed by a friend, Ryan that the game is actually created with a unity engine. So! Here I go at it :). I know it’s quite early and I’m trying to jump and do hurdles before I can even walk. But I think this would help me to develop and learn and find the obstacles I need in more natural sense outside of a protective coursework. And it’s a good way to test what I’ve learned in the course as well. As I have a limited time in the day, I would only be able to work a day a week during the weekend of my free time. But. Here’s what I got so far.
The player can sit, walk, run, attack. Also limits view or up and down by 45 degrees and can look towards sides. Uses Horizontal and Verticals to move directions thus, wasd or the arrow keys. I am using lots of what I learned in the course, using if functions, coroutines, raycast (already a couple times).
RayCast was used to limit the player from double jumping in the air. So script checks if the player is already jumping by checking whether isGround is true or false. and this can be checked through raycasting towards the ground + 0.1 value just in case the player walks up a stair or a slope. The 2nd time the raycast was used was when the player attacks. It checked to what the player is colliding with so that I can input the damage factor into the other colliding object.
More so, in the most recent, I learned more of the camera work. When I was only using the MainCamera, there was an empty cut scenes from the object. So I needed to separate the layer of arms + overall view from the maincamera. So I made a weaponCamera for this. In previous versions of unity, it seems that the camera had the ‘depth only’ function where you can then layer the camera. But that’s been taken out of the function. So I played around a bit and found ‘Overlay’ which then could be stacked* in the main camera to have both of the layers in the scene. Also it relates to the previous raycast of checking colliding object. I had a problem of player detecting its own body for collision. So I had to set all of player, including its children objects to layer, ‘ignore raycast’, then set just the arms back to ‘weapon’ layer for the camera work purposes.
I also don’t have the skill to make my own assets yet. But it also seemed that the assets I got and its directions of use were outdated. When pulling an animator from the asset, it would not create an avatar and reject when I try to drag one either. This was also solved when I went on an inspector, check under Rig. Change the Legacy to Generic and under avatar definition, change from no avatar to create from this model. This will designate the missing avatar problem when brought into the hierarchy. I actually failed when trying to research what the newer term and solutions to problems I had. So I just clicked around and found my way around finding generic option in avatar definition and overlay function in the camera.
Coursework is definitely a priority to me. However, I don’t want to burn myself out and wish to further keep myself motivated and interested while learning. I think this little personal project would do just that for me to keep going :)