PlaceholderGames / 2021-yr2-group-2

CS2S561 2020/1 Group 2
2 stars 0 forks source link

Platform not anchoring player #159

Closed IJCoding closed 3 years ago

IJCoding commented 3 years ago

Should the player wish to stand on the platform it doesn't take them with them.

I've tried out a lot of tutorials online that shows I need to reset the parent of the player however, doing so causes some odd bugs...

IJCoding commented 3 years ago

image

When rotating it causes a warping

IJCoding commented 3 years ago

image

the player only moves with it when this code is commented out

IJCoding commented 3 years ago

image

Otherwise it just stays in place

IJCoding commented 3 years ago

@DoctorMikeReddy I'm not sure how to fix this. Any help would be much appreciated :)!

IJCoding commented 3 years ago

@SharktallicA if you could help that would also be great :D

DoctorMikeReddy commented 3 years ago

You happy to take this one, Khalid?

SharktasticA commented 3 years ago

You happy to take this one, Khalid?

Yeah, no problem. I'll take a look at this on Monday.

SharktasticA commented 3 years ago

My apologies, was busier than I anticipating yesterday. I can take a look this afternoon - @30005209, is there any specific branch I should be checking out?

SharktasticA commented 3 years ago

@30005209 I believe I've got a fix! TLDR - in platformMovement, you need to work out the direction the platform is going and use that along with the speed variable to move the player via the CharacterController during the Update loop for the entire time the player is on the platform.

Steps:

  1. You need to capture a reference of the player (I used the already existing player variable for this) whilst it is on the platform. OnTriggerStay and OnTriggerExit will be sufficient.
  2. Make a Vector3 variable called lastPos in the class's scope, which will store the platform's position from during the last Update loop. Assign it the value of transform.position at the very end of Update.
  3. Make a Vector3 variable called dir in Update, and give it the value of (transform.position - lastPos).normalized. This will be the direction the platform is moving in. I know the heading variable is similar, but trying to use that caused the player to continue moving even when the platform stopped moving.
  4. Whilst the player is indeed on the platform, call CharacterController's Move method and pass in the value of (dir * speed) * Time.deltaTime; This, of course, will move the player as intended.

Player capture and release code: image

The new movement code in Update: image

In case you're wondering/curious why changing the parent caused the deformation - when you set the player's parent as the landing platform through code, the player will be affected the parent's scale values. So if the parent isn't a scale of 1,1,1, it will deform. You could technically work around this issue using a 'middleman' GameObject, but that still wouldn't solve the movement issue. But for future reference for solving such parent-child deformations, you create an empty GameObject in the root/highest level of the hierarchy with a scale of 1,1,1, then make that the child of an object with non 1,1,1 scaling, then place the player as a child of the middleman. When the middleman is assigned to as the child through Unity designer, it recalculates the scale of it automatically to maintain its shape, thus it becomes a stable point of reference for your player.

Anyway, I digress. Hopefully that helps, and lemme know if you need anything else!

DoctorMikeReddy commented 3 years ago

Just remember🧕, where possible, always avoid scaling anything other than in engine primitive shapes away from 1:1:1

IJCoding commented 3 years ago

Thank you so much :D @SharktallicA

And oh @DoctorMikeReddy I think some of us (myself included) have scaled in level so we'll go back and scale in the proper way :D

DoctorMikeReddy commented 3 years ago

Scaling imported items can really mess with the default physics as well :-(

IJCoding commented 3 years ago

I'll go and fix the scaling for the main character :)

lordexishigh commented 3 years ago

Main character's scale has been changed to 1,1,1 using the middleman way khalid recommended above

lordexishigh commented 3 years ago

I changed the scale of the player using a "middleman gameobject" khalid recommended, and in game everything is sized as expected, but in the scene the player appears huge. Any ideas why this happens? @SharktallicA unknown

unknown (1)

IJCoding commented 3 years ago

Just assigned you @lordexishigh as you have already started working on it :)

If you want a hand please - reassign me :D

lordexishigh commented 3 years ago

Ive been trying to get this to work, but ive been having a hard time figuring out a way for the platform to detect the player colliding with it. I tried rigidbody and played around with the code but nothing worked (see video on how it worked with rigidbody). The code works if the player variable is assigned manually, but i cant get it to work with the collision. Any ideas?

When i manually attached the player to the platform:

https://user-images.githubusercontent.com/55789998/111078730-a550e080-84ff-11eb-9bf3-8aefa74c8ae3.mp4

When attached a rigidbody to the platform

https://user-images.githubusercontent.com/55789998/111078720-98cc8800-84ff-11eb-9777-923494dd7108.mp4

SharktasticA commented 3 years ago

I changed the scale of the player using a "middleman gameobject" khalid recommended, and in game everything is sized as expected, but in the scene the player appears huge. Any ideas why this happens? @SharktallicA unknown

unknown (1)

Sorry, I never received an email notification for this tag. If it's still presently an issue, I can take a look soon and get back to you. Will do for the latest one issue from 18 hours ago, too.

lordexishigh commented 3 years ago

Yes please, both are still unsolved. Everything is on the bugfixess branch. @SharktallicA

lordexishigh commented 3 years ago

Hey @SharktallicA, have you had the time to have a look at this?

SharktasticA commented 3 years ago

For the first issue, it seems Armature's scale is always been set to 43.76699 from 437.6699 when the game is played. I couldn't find out exactly what was causing it though - best guess is that some part of the code is manually setting it or perhaps one of your animations modifies scale? I can take a deeper one once I've finished with the other issue.

As for the second issue, I'm still trying solutions. I'll get back to you shortly.

Sorry I don't have any better news, but I've still got some ideas.

lordexishigh commented 3 years ago

i found a fix for the scale bug and had another look on the other issue but couldnt find a solution for it sadly. @SharktallicA

lordexishigh commented 3 years ago

@SharktallicA Any progress on this?

SharktasticA commented 3 years ago

@SharktallicA Any progress on this?

Unfortunately, I've still had no luck. It's puzzling.

lordexishigh commented 3 years ago

I found a solution and but i only made it for only one single platform

lordexishigh commented 3 years ago

Found a solution using a second collision detection which is trigger along with the mesh collision and tweaking the code a bit. This is done so closing issue. Thank you @SharktallicA