» «

# Velocity based on angle

7 replies to this topic
Anthony ok
• ##### Anthony ok

Player Hater

• Members
• Joined: 25 Jun 2012

### #1 Posted 27 November 2013 - 05:27 AM

Hiy guys, i've confused to decide what number for x y in opcode 07D5.
If angle was defined. How to make object (car) move straight based on angle direction.
is there any formula to find the correct number for x y value?

Jack
• ##### Jack

aka Hollywood Jack

• Feroci
• Joined: 06 Dec 2011

### #2 Posted 27 November 2013 - 07:13 AM

You may also try with:
```02F7: cos 0@ store_to 1@   // x
02F6: sin 0@ store_to 2@   // y

02F8: get_car_forward_x 0@ store_to 1@  // x
02F9: get_car_forward_y 0@ store_to 2@  // y

077D: 1@ = car 0@ x_angle
06BE: 2@ = car 0@ y_angle
0174: 3@ = car 0@ Z_angle```

Wesser
• ##### Wesser

The complexity simplifier, the efficiency optimizer.

• Feroci
• Joined: 19 Aug 2006
• Contribution Award [Mods]

### #3 Posted 27 November 2013 - 09:25 AM Edited by Wesser, 27 November 2013 - 01:09 PM.

It is a basic trigonometric calculation. You can obtain the normalized vector by an angle and multiply it by a distance. The more the distance is, the more the velocity will be. Follow this code snippet:
```const
DISTANCE_X = -0.01
DISTANCE_Y = 0.01
DISTANCE_Z = 0.0
end
var
0@: Float // Angle
1@: Float // Sine->X
2@: Float // Cosine->Y
3@: Float // Z
end
// Given angle 0@ and distance 1@.
02F6: 1@ = sine 0@
02F7: 2@ = cosine 0@
1@ *= DISTANCE_X
2@ *= DISTANCE_Y
3@ = DISTANCE_Z
// Now XYZ are stored into 1@, 2@ and 3@.```

Jack
• ##### Jack

aka Hollywood Jack

• Feroci
• Joined: 06 Dec 2011

### #4 Posted 27 November 2013 - 10:17 AM

And if you want the object to act like for exmpl an asteroid or a missile you also need to define a Z trajectory. That would make the object to move in 3D space as well (not just in 2D)  .

Anthony ok
• ##### Anthony ok

Player Hater

• Members
• Joined: 25 Jun 2012

### #5 Posted 27 November 2013 - 12:00 PM

thanks guys, i have a try it for sparrow to get a fast velocity but, why the velocity is too fast i cant control the speed, and direction is only once correct, after that the direction not necessarily the direction

This is an error in the preparation of the script?

try this my error script

```thread 'UFO_SPEED'

:UFO_SPEED_19
wait 0
if or
00E1:   player 0 pressed_key 17
00E1:   player 0 pressed_key 6
00E1:   player 0 pressed_key 4
else_jump @UFO_SPEED_19

:UFO_SPEED_52
wait 10
if
Player.Defined(\$PLAYER_CHAR)
else_jump @UFO_SPEED_52
if
Actor.DrivingVehicleType(\$PLAYER_ACTOR, #SPARROW)
else_jump @UFO_SPEED_19
03C0: 10@ = actor \$PLAYER_ACTOR car

:UFO_SPEED_336
wait 0
if
00E1:   player 0 pressed_key 17
else_jump @UFO_SPEED_364
9@ = Car.Angle(10@)
02F7: 2@ = cosine 11@
02F6: 1@ = sine 11@
1@ *= 0.5
2@ *= 0.5
3@ = 0.0
jump @UFO_SPEED_501

:UFO_SPEED_364
if and
00E1:   player 0 pressed_key 4
80E1:   not player 0 pressed_key 6
else_jump @UFO_SPEED_418
1@ = 0
2@ = 0
3@ = 0.05
jump @UFO_SPEED_501

:UFO_SPEED_418
if and
00E1:   player 0 pressed_key 6
80E1:   not player 0 pressed_key 4
else_jump @UFO_SPEED_465
3@ = -0.05
2@ = 0
1@ = 0

:UFO_SPEED_465
if and
80E1:   not player 0 pressed_key 4
80E1:   not player 0 pressed_key 17
80E1:   not player 0 pressed_key 6
else_jump @UFO_SPEED_501
jump @UFO_SPEED_19

:UFO_SPEED_501
07D5: set_car 10@ velocity_in_direction_XYZ 1@ 2@ 3@ rotation_velocitiesXY 0.0 0.0 unk 0.0
jump @UFO_SPEED_336

```

Wesser
• ##### Wesser

The complexity simplifier, the efficiency optimizer.

• Feroci
• Joined: 19 Aug 2006
• Contribution Award [Mods]

### #6 Posted 27 November 2013 - 12:53 PM

11@ is unused in the whole script, 9@ handles the vehicle's angle. Moreover, the distance of the X value should be negative. If you want to move your vehicle at an acceptable speed, divide the current distance by 10.

Anthony ok
• ##### Anthony ok

Player Hater

• Members
• Joined: 25 Jun 2012

### #7 Posted 26 December 2013 - 04:07 PM

thaks wesser its work, btw how if give z direction to?

sin or cosine?

Anthony ok
• ##### Anthony ok

Player Hater

• Members
• Joined: 25 Jun 2012

### #8 Posted 26 December 2013 - 04:23 PM

thanks guys, i use sin for z velocity based on x angel.

done

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users