BTW,
I can make it work using atan2, sin & cos with the following. Note that I want to return what I want to add to m_objEntity.. That's why the last two lines are commented.
Dim intSpeed As Integer = 4
Dim directionX As Double
Dim directionY As Double
Dim speedX As Double
Dim speedY As Double
Dim dblAngle As Double
directionX = m_objTarget.Left - m_objEntity.Left
directionY = m_objTarget.Top - m_objEntity.Top
dblAngle = Math.Atan2(directionY, directionX)
speedX = intSpeed * Math.Cos(dblAngle)
speedY = intSpeed * Math.Sin(dblAngle)
'm_objEntity.Left += CInt(speedX)
'm_objEntity.Top += CInt(speedY)
Return New Point(CType(speedX, Integer), CType(speedY, Integer))
und3rd06
Wow it's good to see a thread about this.
My mind is "rusty" math wise. it's been a while.
I am trying to make my object go towards another but it doesn't seem to work. Can someone see what I am doing wrong ?
In the blow example I simply want to return the new point of m_objEntity. I want to move m_objEntity towards m_objTarget. The .Left propety is = "x" and the Top property is for "y"
Dim intSpeed As Integer = 4
Dim length As Double
Dim directionX As Double
Dim directionY As Double
Dim ReturnX As Double
Dim ReturnY As Double
directionX = m_objEntity.Left - m_objTarget.Left
directionY = m_objEntity.Top - m_objTarget.Top
length = Math.Sqrt((directionX * directionX) + (directionY * directionY))
' normalize (make it 1 unit length)
directionX = directionX / length
directionY = directionY / length
' scale to our desired speed
directionX = directionX * intSpeed
directionY = directionY * intSpeed
ReturnX = m_objTarget.Left + directionX
ReturnY = m_objTarget.Top + directionY
Return New Point(CType(ReturnX, Integer), CType(ReturnY, Integer))