My Student Needs Your Help With His Game

csdunit3

#1

This is beyond my knowledge level. I’m sharing his explanation with you and a link to his game. Thanks in advance for your help

https://studio.code.org/projects/gamelab/6v7RywvENT9hhk1-_3qUF7bu5jqlV2wtXQnGovK5ybs

I am coding a game in which you are controlling a motorcycle sprite. You can drive it around the screen. There is a missile in the game that will CHASE the player. I’m using the setSpeedAndDirection block along with pointTo to make the missile fly towards the player. When I run the game the missile does POINT to the player but only MOVES towards the starting point of the player. I have this code in the draw loop as a function. Your example for setSpeedAndDirection shows that the sprite will move in the updated direction it is given. Should this be the same with pointTo? I intend for the missile sprite to follow or chase the player. Do I need to use some other code to make this happen? Should this be the same with pointTo?


#2

The missile.pointTo() command sets the missile’s rotation, but it doesnt return that rotation. The missile.setSpeedAndDirection() command needs to take both a speed and a heading (in this case, the missile’s rotation). So in order to get the effect your student is looking for, they’d need to first use missile.pointTo(player.x, player.y) to update the missile’s rotation, and then use missile.rotation inside the missile.setSpeedAndDirection() command. eg:

missle.pointTo(player.x,player.y)
missle.setSpeedAndDirection(1, missle.rotation);

#3

Thank you so much for your quick reply. I’m learning SO much!