Rick has the same problem

I noticed that in this lecture Rick has the same problem I was facing that the AddForce method for some reason ignores the X axis an or teleports the player instead of applying a force.

I googled and many people seem to have this same problem for different reasons. What could be causing it?

Hi,

Could you please point me to the minute in the video where you saw that Rick got the same problem as you?

Yes, it’s at 06:45.

I attempted to get the player character to fly backwards by using Addforce with a vector of (-jumpforce, jumpforce) but no matter what I do I get this same behavior where the character jumps directly upwards.

Rick’s deathKick Vector is also set to 20,20 so I would assume it should add velocity at a 45 degree angle to the character? And if it were -20,20 then i should be diagonally upwards and left.

I’ve watched the part in the video named “How To Create Hazards” to which the tag in your thread refers. At around the 6:45 mark, we just see the enemy, not the player. I’m afraid I still do not know what you mean.

Regarding the death kick, you are right. If the deathKick is set to (20, 20), the player is supposed to jump “up-right”. With x = -20, he’s supposed to jump “up-left”.

And we are overriding the velocity with this line: myRigidbody.velocity = deathKick;

Since (20, 20) is fairly fast, approximately 28 WU/s, it might be that the player just appears to be teleporting because he’s moving so fast.

My mistake. I accidentally already switched lectures before I asked this question.

The problem is in the previous lecture at 6:45. The lecture is called “Player Death State”

Thank you! I hope I watched the part you meant. :slight_smile:

Here is what I saw in the video: The player’s velocity gets set to deathKick (20, 20). He starts flying upwards and right as expected. Then he collides with the enemy’s collider and bounces off. Bouncing off means “the opposite x-direction” (in this case, not in general).

The observed behaviour makes sense to me because we do not apply the “death kick” velocity all the time but use it to launch the player if you will. After we did that, the physics simulation controls the player.

I hope my description made sense so far.

I was watching the video with the normal speed (1x). If you sped the video up, it might be possible that the player appears to be teleporting to the left. Could you please rewatch the part as of the 6:44 mark and let me know if you are now able to see the same as I?

I believe in the next video I saw Ricks deatKick work properly. I still for some reason have this problem in my code where the horizontal axis on the deathKick is for some reason ignored :smiley: No idea why :smiley: :smiley: :smiley:

Please log the deathKick into your console to see what its values are. Do not rely on what you see in the Inspector. Also log the velocity into your console in Update to see if it changes after the deathKick was assigned.

If the values are as expected, make the player “die” without an enemy. Just execute the “deathKick” code at the beginning of the game to see if it works. If it works, maybe the enemy collider prevents the player from moving along the x-axis.

Yes, problem solved. I has logged the “deathKick” vector before but after logging it in Update I realized that while it was (10,10) on the function call it was set to x=0 immiediately after.

The Update function runs the Run() method which has a x-velocity * moveInput.x which is = 0 when the player is dead so my adding a if(!hasdied) around the Run() method the behavior is now as I wished and the character flyes off at a 45-degree angle opposite the direction it’s facing.

Thank you for getting me to re-try logging in a new way so the error presented itself.

Fantastic! I’m glad you found the issue.

Have a nice weekend! :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms