Object not moving to angle

This is a discussion on Object not moving to angle within the C Programming forums, part of the General Programming Boards category; I am having problems moving an object in the direction of the angle that Its moving in. I can't see ...

  1. #1
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218

    Object not moving to angle

    I am having problems moving an object in the direction of the angle that Its moving in. I can't see whats wrong with it, but the output is definitely wrong.

    Here where I declare and create an object:
    Code:
    struct Sprite
    {
        float x, y;
        int w, h;
        int r, g, b;
        float angle, speed;
    }; typedef struct Sprite Sprite;
    Sprite thing;
    Here I initialize some variables:
    Code:
       thing.x=320; thing.y=240; 
       thing.w=10; thing.h=10;
       thing.r=255; thing.g=0; thing.b=0;
       thing.angle=90; thing.speed=2;
    With an angle of 90 degrees it should move downwards, but I'm finding it moves to the left as well (as if around 110 degrees or so). Heres where I move it:
    Code:
        float dx, dy;
        dx=cos(thing.angle);
        dy=sin(thing.angle);
        thing.x+=(thing.speed*dx);
        thing.y+=(thing.speed*dy);
    Can anyone see whats going wrong here?

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    I had a look at this and tried converting the angle to radians first, which worked

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Object destroy itself?
    By cminusminus in forum C++ Programming
    Replies: 28
    Last Post: 03-27-2008, 01:08 AM
  2. ERRPR: Object reference not set to an instance of an object
    By blackhack in forum C++ Programming
    Replies: 1
    Last Post: 07-13-2005, 05:27 PM
  3. Set Classes
    By Nicknameguy in forum C++ Programming
    Replies: 13
    Last Post: 10-31-2002, 01:56 PM
  4. Set Classes
    By Nicknameguy in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2002, 07:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21