Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs

ct.js

Create cool 2D games with a free game editor! · By Cosmo Myzrail Gorynych

Homing Missile

A topic by BoredThing created 58 days ago Views: 66 Replies: 2
Viewing posts 1 to 2
(1 edit)

I'm attempting to make a homing missile sort of thing, and it won't work. Being a beginner, I'm not understanding why. Here's the code:

var degrees = ct.u.pointDirection(this.x, this.y, player);
this.rotation = degrees; 
this.direction = this.rotation;
this.speed = 5;

var player = ct.types.list["Player"][0]; 
if (player) {
    return player.x, player.y;
}

Developer

First:

var degrees = ct.u.pointDirection(this.x, this.y, player);

It should be:

var degrees = ct.u.pointDirection(this.x, this.y, player.x, player.u);

Second:

var player = ct.types.list["Player"][0];
It should go before

you use player variable for homing code.



Third:

if (player) {
    return player.x, player.y;
}
This does nothing and is not needed (:
(+1)

Thanks so much! I got it to work!

By the way, you typed in player.u instead of player.y :)