Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Velocity[a] is a Vector3 type (all doubles), Proximity is a double as is Influence. The highlighted code produces a cannot convert double to float error... I have tried (double)0 and that did not solve the problem. Any ideas?

 

Velocity[a] = (new Vector3(
   [color="Red"]Proximity.X != 0[/color] ? Velocity[a].X + (1/(Influence * Proximity.X)) : Velocity[a].X, 
   [color="Red"]Proximity.Y != 0[/color] ? Velocity[a].Y + (1/(Influence * Proximity.Y)) : Velocity[a].Y,
   [color="Red"]Proximity.Z != 0[/color] ? Velocity[a].Z + (1/(Influence * Proximity.Z)) : Velocity[a].Z
));

Edited by snarfblam
  • Leaders
Posted

You're code is a bit hard to read. While that might sound nit-picky, and it's a subjective thing, when code is more readable, it is easier to understand and reason about it, especially at a glance. It also helps us help you.

 

The documentation for Vector3 states that the fields are floats, not doubles. You either need to cast to float, or make sure that all of your variables are floats rather than doubles. Something like this should work.

 

Velocity[a] = (new Vector3(
   Proximity.X != 0 ? 
       [color="Blue"](float)([/color]Velocity[a].X + (1/(Influence * Proximity.X))[color="Blue"])[/color] : 
       Velocity[a].X, 
   Proximity.Y != 0 ? 
       [color="Blue"](float)([/color]Velocity[a].Y + (1/(Influence * Proximity.Y))[color="Blue"])[/color] :
       Velocity[a].Y,
   Proximity.Z != 0 ? 
       [color="Blue"](float)([/color]Velocity[a].Z + (1/(Influence * Proximity.Z))[color="Blue"])[/color] :
       Velocity[a].Z
));

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...